From f58799678124f5bb6fd68ae684cd64c214a5413d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Fri, 18 Apr 2014 04:37:39 +0200 Subject: [PATCH] =?UTF-8?q?[backuppc]=20G=C3=A9n=C3=A9ration=20automatique?= =?UTF-8?q?=20de=20config=20:=20script=20appel=C3=A9=20par=20bcfg2=20sur?= =?UTF-8?q?=20babar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backups/generate_configs.py | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 backups/generate_configs.py diff --git a/backups/generate_configs.py b/backups/generate_configs.py new file mode 100755 index 00000000..933da9de --- /dev/null +++ b/backups/generate_configs.py @@ -0,0 +1,60 @@ +#!/bin/bash /usr/scripts/python.sh +# -*- coding: utf-8 -*- +# +# Script de génération des configs backuppc sur babar +# Doit être exécuté par root. +# Plein de trucs sont hardcodés, c'est chiant, il faudrait encore +# optimiser tout ça +# +# Boucle sur les divers serveurs pour générer leurs configs dans des fichiers perl +# Fait la même chose pour les homes, en fractionnant ceux-ci suivant la config +# donnée par backups.py +# +# Auteur : Pierre-Elliott Bécue +# Licence : GPLv3 + +import sys +sys.path.append("/etc/backuppc/config/") +import backups +import os +import pwd +import grp + +rootpath = "/etc/backuppc/" + +if __name__ == "__main__": + root = pwd.getpwnam('root').pw_uid + 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 +};""" % {'shares' : ", ".join(backup_folders.keys()), 'excludes' : "\n ".join(["'%s' => ['lost+found']," % nom for nom in backup_folders.keys()])}) + os.chmod(rootpath + hoteRsync + ".pl", 0644) + os.chown(rootpath + hoteRsync + ".pl", root, wwwdata) + + for homeDir in backups.HomeHosts: + with open(rootpath + homeDir + ".pl", "w") as fichier: + fichier.write("""# Ces fichiers pointent vers zbee et servent à backuper les homes en séparé. +$Conf{ClientTimeout} = 86400; + +$Conf{XferMethod} = 'tar'; +$Conf{TarShareName} = ['/home-adh']; +$Conf{TarClientPath} = '/bin/tar'; +$Conf{SshPath} = '/usr/bin/ssh'; + +$Conf{ClientNameAlias} = '%(myip)s'; + +$Conf{BackupFilesExclude} = { + '/home-adh' => [ + '/lost+found', + '%(gimmemoar)s', + ], +};""" % {'gimmemoar' : "', '".join(backups.HomeExclude[homeDir]), 'myip':backups.ipnfs}) + os.chmod(rootpath + homeDir + ".pl", 0644) + os.chown(rootpath + homeDir + ".pl", root, wwwdata)