Backup Script

For my backup i was using a tool that just became “DEPRECATED”, so i move on writing my own python script to replace it.
It aims to be simple… In the config file, we declare some “sources”, each one is transform into an archive. Also, we create some backup “destinations”. And then, we associate source to destination.

here’s an example

<?xml version="1.0" encoding="UTF-8"?>
<jsb>
	<configuration>
		<workingdir>.</workingdir>
		<lib>backupMod</lib>
	</configuration>
	<sources>
		<source name="rep" type="directory" path="/var/www/testbackup" gzip="true" />
		<source name="mydb" type="mysql" host="localhost" user="username" passwd="mypass" database="oneDb" />
	</sources>
	<destinations>
		<destination name="dest" type="directory" path="/var/save/" format="%Y/%m/%d" />
		<destination name="ftp_dest" type="ftp" host="myhost" user="myuser" passwd="mypass" format="%Y/%m/%d" />
	</destinations>
	<backups>
		<backup source="rep" destination="dest" />
		<backup source="rep" destination="ftp_dest" />
		<backup source="mydb" destination="ftp_dest" />
	</backups>
</jsb>

In this config, we save “/var/www/testbackup” in a local directory and on ftp server, and the db “OneDB” is send to the FTP destination. In the process we create the directory tree to save our archives : “YYYY/MM/DD/archivename”

You must have seen the line “backupMod, indeed, as we want to allow more flexibility, you can create your own backup functions, and add them into librairies used by the script. You must follow this naming :
for a function creating an archive from a source : Source_[Type]
for a function moving the archive onto the destination : Destination_[Type]
And, a source function must return the archive path

You can find the script here : https://github.com/belotn/jsb

+2013/25/02
add max retention time for a destination in days : attribute prune
<destination type=”directory” path=”/var/tmp” prune=”7″/>
archive older than 7days will be remove.