Permalink
Browse files

rdiff-backup: improvements+clean-up

 * removed old and obsolete examples in README
 * switch README file in reStructuredText markup lauguage
 * convert the backup script to an ERB template
  • Loading branch information...
1 parent dcdef2a commit 7c7dcd80afdc2d271de204b34b10c2a7dee5db72 @mbornoz mbornoz committed Nov 10, 2011
Showing with 10 additions and 247 deletions.
  1. +0 −93 README
  2. +10 −0 README.rst
  3. +0 −154 files/usr/local/sbin/multiprocessing-rdiff-backup.py
View
93 README
@@ -1,93 +0,0 @@
-Introduction/Notes
-==================
-
-This module provide a simple way to manage a central backup
-server based on rdiff-backup.
-
-This module is under development !
-
-Usage
-=================
-
-node 'central-backup-server' {
-
- # backup server settings
- $rdiff_backup_max_threads = 10
- $rdiff_backup_logs_dir = "/var/log/rdiff-backup"
- $rdiff_backup_smtp_server = "localhost"
- $rdiff_backup_enable_mail = 1
- $rdiff_backup_mail_from = "backupserver@domain.com"
- $rdiff_backup_mail_to = "backupmanager@domain.com"
-
- # copy and modify one of these classes to install another version
- rdiff-backup::server::install { ["0.13.4","1.1.15","1.1.5"]:
- ensure => present
- }
- # we want to remove one version? ok:
- rdiff-backup::server::install {"1.2.5":
- ensure => absent,
- }
-
- # args = rdiff-backup arguments (http://www.nongnu.org/rdiff-backup/rdiff-backup.1.html)
- rdiff-backup::conf{$fqdn:
- ensure => present,
- version => "1.2.5",
- source => "/",
- destination => "/backup/${fqdn}",
- args => "--print-statistics --include '/etc' --exclude '/'",
- retention => "5D",
- }
-
- # collect exported ressources
- Rdiff-backup::Conf <<||>>
-
- # collect public keys
- Sshkey <<||>>
-
- file {"/root/.ssh/your_private_key_id_rsa": # the key used in --remote-schema below
- ensure => present,
- owner => root,
- group => root,
- mode => 600,
- content => "-----BEGIN RSA PRIVATE KEY-----
-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-...
-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
------END RSA PRIVATE KEY-----\n",
- }
-
-}
-
-node 'one-client-to-backup' {
-
- include rdiff-backup::client # install default package of your distribution
-
- @@rdiff-backup::conf{$fqdn:
- ensure => present,
- version => "1.2.5", # a fine improvement will be to get rdiff-backup version with a fact
- source => "root@${fqdn}::/",
- destination => "/backup/${fqdn}",
- args => "--remote-schema 'ssh -t -i /root/.ssh/your_private_key_id_rsa %s' --print-statistics --exclude '/proc' --exclude '/dev' --exclude '/mnt' --exclude '/media',
- retention => "30D",
- }
-
- # export public key of this node
- @@sshkey {"$fqdn": type => rsa, key => $sshrsakey }
-
- # use ssh-keygen to generate SSH keys without passphrase and put the public key here
- ssh_authorized_key {"multithreaded-rdiff-backup":
- ensure => present,
- type => "ssh-rsa",
- key => "AAAA ... BIwAAAQEA0PPAW==", # your public SSH key
- user => root,
- options => [
- "from=\"124.44.55.66\"", # IP of your central backup server
- "command=\"rdiff-backup --server\"",
- "no-pty",
- "no-port-forwarding",
- "no-X11-forwarding",
- ],
- }
-
-}
View
@@ -0,0 +1,10 @@
+==========================
+rdiff-backup Puppet module
+==========================
+
+This module is provided to you by Camptocamp_.
+
+.. _Camptocamp: http://www.camptocamp.com/
+
+For more information about rdiff-backup see http://www.nongnu.org/rdiff-backup/
+
@@ -1,154 +0,0 @@
-#!/usr/bin/env python
-
-import os
-import time
-import sys
-import glob
-import shlex
-import subprocess
-from optparse import OptionParser
-import ConfigParser
-from os.path import join
-from multiprocessing import Pool
-from commands import getstatusoutput
-
-_RBDIR = "/opt/rdiff-backup"
-_CONFIG = "/etc/multiprocessing-rdiff-backup.conf"
-_LOCKFILE="/tmp/multiprocessing-rdiff-backup.running"
-
-def backup(host):
-
- logFile = "/var/log/rdiff-backup/%s-%s.log" % (
- host['host'],
- time.strftime("%d-%m-%Y", time.localtime())
- )
-
- args = []
- args.append("%s/rdiff-backup-%s/bin/rdiff-backup" % (_RBDIR, host['version']))
- args.extend(shlex.split(host['args']))
- args.append(host['source'])
- args.append(join(host['destination'], host['host']))
-
- env = []
- for l in ["lib", "lib64"]:
- env.append("%s/rdiff-backup-%s/%s/python%s.%s/site-packages" % (
- _RBDIR, host['version'], l, sys.version_info[0], sys.version_info[1]))
-
- proc = subprocess.Popen(
- args,
- env={"PYTHONPATH": ":".join(env)},
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- close_fds=True)
-
- status = os.waitpid(proc.pid,0)[1]
- output = proc.stdout.read()
- if status: output += proc.stderr.read()
-
- if not status:
- start_time = time.time()
- args = []
- args.append("%s/rdiff-backup-%s/bin/rdiff-backup" % (_RBDIR, host['version']))
- args.extend(["--remove-older-than", host['retention'], "--force", join(host['destination'], host['host'])])
-
- proc = subprocess.Popen(
- args,
- env={"PYTHONPATH": ":".join(env)},
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- close_fds=True)
-
- status = os.waitpid(proc.pid,0)[1]
- elapsed_time = time.strftime("%H:%M:%S", time.gmtime(time.time()-start_time))
- output += proc.stdout.read()
- output += "DeletingIncrementsElapsedTime: %s\n\n" % elapsed_time
- if status: output += proc.stderr.read()
-
- # writes a logfile with rdiff-backup stdin and stderr
- flog = open(logFile, 'w')
- flog.write(output)
- flog.write("RDIFF-BACKUP-EXIT-STATUS=%s\n" % status)
- flog.close()
-
-def getBackupList(pool_dests, dest="",):
- backups = []
- backupList = glob.glob('/etc/rdiff-backup.d/*.conf')
- for backup in backupList:
- config = ConfigParser.ConfigParser()
- config.read(backup)
- if config.get('hostconfig', 'destination') in pool_dests:
- backups.append(dict(config.items('hostconfig')))
- else:
- print "Bypass host %s cause it doesn't match an existing pool destination_dir!" % config.get('hostconfig', 'host')
-
- if dest:
- return filter(lambda x:x['enable'].lower() == "true" and x['destination'] == dest, backups)
- else:
- return filter(lambda x:x['enable'].lower() == "true", backups)
-
-def addlock():
- if os.path.exists(_LOCKFILE):
- print "multiprocessing-rdiff-backup --all is already running!\n"
- sys.exit(1)
- else:
- f = open(_LOCKFILE,'w')
- f.write("multiprocessing-rdiff-backup session is running!\n")
- f.close()
-
-def dellock():
- if os.path.exists(_LOCKFILE):
- os.remove(_LOCKFILE)
-
-def readPoolConfig():
- pools = {}
- if not os.path.exists(_CONFIG):
- print "Main configuration %s not found!" % mainConfig
- sys.exit(1)
- config = ConfigParser.ConfigParser()
- config.read(_CONFIG)
- for section in config.sections():
- pools[section] = dict(config.items(section))
- return pools
-
-if __name__=="__main__":
-
- # only root can run this script
- if os.getuid():
- print "not root!"
- sys.exit(1)
-
- options = OptionParser(version="1.0")
- options.add_option("--host", dest="host", help="launch backup for <host> only")
- options.add_option("--all", action="store_true", help="launch backup for all hosts")
- (opt, args) = options.parse_args()
-
- if not (opt.host or opt.all):
- options.print_help()
- sys.exit(1)
-
- pool_config = readPoolConfig()
- pool_destination_dirs = [ y['destination_dir'] for x,y in pool_config.items() ]
-
- if opt.host:
- backups = getBackupList(pool_dests=pool_destination_dirs)
- backups = filter(lambda x: x['host'] == opt.host, backups)
- if not backups:
- options.error("Host %s not found!" % opt.host)
-
- pool = Pool(processes=1)
- pool.map(backup, backups)
-
- else:
- addlock()
- pools = []
- for key, value in pool_config.items():
- backups = getBackupList(pool_destination_dirs, pool_config[key]['destination_dir'])
- pool = Pool(processes=int(value['max_process']))
- pool.imap_unordered(backup, backups)
- pool.close()
- pools.append(pool)
-
- [p.join() for p in pools]
-
- if opt.all:
- dellock()

0 comments on commit 7c7dcd8

Please sign in to comment.