Today I need to find a way to do some backup on an FTP server. Of course there is a lot of way to do that, but I need something automatic that does some full (monthly) and incremental (daily) backup. I decided to use duplicity because it’s a really simple and effective software. The main issue, is that duplicity command line is a bit hard to remember for me. So why not simply write a simple python script that does the job for me.
So here, we are :
#!/usr/bin/python # Edit DATA and DEST DATA='/var/www' DEST='ftp://username:email@example.com/backup' import os import sys def backup(b_type='incr'): dup_cmd ='nice -n 19 duplicity %s --volsize 512 --no-encryption --asynchronous-upload ' % (b_type,) temp = '%s %s %s' % (dup_cmd,DATA,DEST) os.system(temp) def info(): dup_cmd='duplicity collection-status %s' % (DEST) os.system(dup_cmd) def list_files(): dup_cmd='duplicity list-current-files %s' % (DEST) os.system(dup_cmd) def clean(): dup_cmd='duplicity remove-all-but-n-full 1 --force %s' % (DEST) os.system(dup_cmd) def usage(): print "%s [-incr|-full|-list|-info|-clean]" % sys.argv if __name__=='__main__': if len(sys.argv) > 1: if sys.argv == '-incr': backup('inc') elif sys.argv == '-full': backup('full') elif sys.argv == '-info': info() elif sys.argv == '-list': list_files() elif sys.argv == '-clean': clean() else: usage() else: usage()
Please note that I disabled the PGP encryption for this backup. Mainly because, I don’t want to deal w/ lost keys when I will need to restore the backup. But this can be done easily. I will post a complete guide if someone ask.
The next step call the script in cron.d for example with something like this : 30 3 * * *
Feel happy no more stress with backup ;)