backups des homes sur une machine séparée

This commit is contained in:
Pierre-Elliott Bécue 2014-12-16 01:47:33 +01:00
parent f62b563d0e
commit 803c1e8a4a

View file

@ -19,44 +19,45 @@ import backups
import os import os
import pwd import pwd
import grp import grp
import socket
rootpath = "/etc/backuppc/" rootpath = "/etc/backuppc/"
if __name__ == "__main__": if __name__ == "__main__":
root = pwd.getpwnam('root').pw_uid root = pwd.getpwnam('root').pw_uid
wwwdata = grp.getgrnam("www-data").gr_gid wwwdata = grp.getgrnam("www-data").gr_gid
for hoteRsync in backups.RsyncHosts:
backup_folders = backups.RsyncHostsToBackup[hoteRsync]
backup_folders.update(backups.RsyncClassicalDirs)
for excluded in backups.RsyncHostsToExclude[hoteRsync]:
backup_folders.pop(excluded)
with open(rootpath + hoteRsync + ".pl", "w") as fichier:
fichier.write("""$Conf{RsyncShareName} = ['%(shares)s'];
$Conf{BackupFilesExclude} = {
%(excludes)s
};
$Conf{IncrPeriod} = %(incr)s; if "babar" in socket.getfqdn():
$Conf{FullPeriod} = %(full)s;""" % {'shares' : "', '".join(backup_folders.keys()), 'excludes' : "\n ".join(["'%s' => ['lost+found']," % nom for nom in backup_folders.keys()]), 'incr': backups.RsyncPeriods[hoteRsync][0], 'full': backups.RsyncPeriods[hoteRsync][1]}) for hoteRsync in backups.RsyncHosts:
if backups.DumpPreUserCmd[hoteRsync]: backup_folders = backups.RsyncHostsToBackup[hoteRsync]
fichier.write("""\n$Conf{DumpPreUserCmd} = '%(dp)s';""" % {'dp':backups.DumpPreUserCmd[hoteRsync],}) backup_folders.update(backups.RsyncClassicalDirs)
os.chmod(rootpath + hoteRsync + ".pl", 0644) for excluded in backups.RsyncHostsToExclude[hoteRsync]:
os.chown(rootpath + hoteRsync + ".pl", root, wwwdata) backup_folders.pop(excluded)
with open(rootpath + hoteRsync + ".pl", "w") as fichier:
fichier.write("""$Conf{RsyncShareName} = ['%(shares)s'];
$Conf{BackupFilesExclude} = {
%(excludes)s
};
for homeDir in backups.HomeHosts: $Conf{IncrPeriod} = %(incr)s;
with open(rootpath + "home-" + homeDir + ".pl", "w") as fichier: $Conf{FullPeriod} = %(full)s;""" % {'shares' : "', '".join(backup_folders.keys()), 'excludes' : "\n ".join(["'%s' => ['lost+found']," % nom for nom in backup_folders.keys()]), 'incr': backups.RsyncPeriods[hoteRsync][0], 'full': backups.RsyncPeriods[hoteRsync][1]})
fichier.write("""# Ces fichiers pointent vers zbee et servent à backuper les homes en séparé. if backups.DumpPreUserCmd[hoteRsync]:
$Conf{ClientTimeout} = 86400; fichier.write("""\n$Conf{DumpPreUserCmd} = '%(dp)s';""" % {'dp':backups.DumpPreUserCmd[hoteRsync],})
os.chmod(rootpath + hoteRsync + ".pl", 0644)
os.chown(rootpath + hoteRsync + ".pl", root, wwwdata)
$Conf{XferMethod} = 'tar'; if "omnomnom" in socket.getfqdn():
$Conf{TarShareName} = ['/home-adh/%(share)s']; for homeDir in backups.HomeHosts:
$Conf{TarClientPath} = '/bin/tar'; with open(rootpath + "home-" + homeDir + ".pl", "w") as fichier:
$Conf{SshPath} = '/usr/bin/ssh'; fichier.write("""# Ces fichiers servent à backuper les homes en séparé.
$Conf{ClientTimeout} = 86400;
$Conf{ClientNameAlias} = '%(myip)s'; $Conf{XferMethod} = 'tar';
$Conf{TarShareName} = ['/home/%(share)s'];
$Conf{TarClientPath} = '/usr/bin/env LC_ALL=C sudo /usr/local/bin/backuppc_tar -v -f - -C $shareName';
$Conf{BackupFilesExclude} = { $Conf{BackupFilesExclude} = {
'/home-adh/%(share)s' => ['lost+found'], '/home-adh/%(share)s' => ['lost+found'],
};""" % {'share' : homeDir, 'myip' : backups.ipnfs}) };""" % {'share' : homeDir, 'myip' : backups.ipnfs})
os.chmod(rootpath + "home-" + homeDir + ".pl", 0644) os.chmod(rootpath + "home-" + homeDir + ".pl", 0644)
os.chown(rootpath + "home-" + homeDir + ".pl", root, wwwdata) os.chown(rootpath + "home-" + homeDir + ".pl", root, wwwdata)