What is this about ? ******************** Do you backup your machine every day ? I thought not, well this script will help you backup your important files do another part of your machine or somewhere NFS mounted. This script can also take a copy of your mysql databases. The script does a full backup each Monday and incremental backups on the rest of the week. Backups that are more than 14 days are removed. Backups are stored as bzip2ed cpio files. This script is not the ultimate backup script, but is quick & easy to get going. This is designed to be run from cron. Installation ************ Copy the file BackupToDisk to /usr/local/bin and make it executable. Note that this script used the Korn Shell (ksh), you may need to install this on your machine. Put a line like the following in root's crontab: 10 5 * * * /usr/local/bin/BackupToDisk -dc -D 'etc home' The list of directories is specified with the -D option on the crontab entry above. Review the options, you may want to use other ones. You probably ought to occasionally copy the full backup (the Monday one) somewhere else in case you loose the entire machine. Options ******* -b dir Base directory where backups are written, default: /mnt/backup/ The value MUST have a trailing '/' on it - unless you really know what you are doing. -c Clean out /mnt/backup/daily/, remove anything more than 14 days old. But not the directories referred to by LATEST-FULL and LATEST-INCREMENTAL. -C nn Change the clean period (see -c option) to nn days -d Daily backup, ie write to /mnt/backup/daily/, incremental, full on Mondays -D dirs List of directories to backup - this option must be given. -F Do NOT (find) generate a list of every file on the machine. By default a list names of all the files on the machine is generated in the file AllFiles.bz2 (bzip2ed as you can see) this option stops that. -f, --full Full backup - regardless of the day of week -m, --mysql-dump Perform mysqldump, default not done -M, --no-mysql-dump Don't perform mysqldump -o Copy output to the current stderr as well as something in /var/log/backups/ Output will go to stderr anyway if the program is run interctively. Output will go to stderr if something goes wrong. -p dbs, --mysqlDbs=dbs dump mysql databases dbs - a space separated list (in quotes) --postgres-dump PostgreSQL database dump, default all databases --postgres-dbs=database-list PostgreSQL database dump, databases listed must be space separated --postgres-user=user PostgreSQL user to perform the dump as, default '$postUser' --postgres-host=name Host that has the PostgreSQL server, or socket directory (see psql --host), default '$postHost' --separate-database Dump databases into separate files. -x, --help eXplain -- give a help message. Archive Format ************** One file per backup directory (as per -D option) is created and stored in a daily unique directory. The archive is cpio compressed using bzip2. There may be several other files created. These files are stored in a separate directory for every day, eg: /mnt/backup/daily/20071010/ Files in the archive directory ****************************** AllFiles.bz2 This is a list of all the files on the machine at the time of backup. MysqlDump.bz2 The mysqldump of all databases (if -m). MysqlDump_Foo.bz2 Mysqldump of database Foo if --separate-database. PostgreSQLdump_all.bz2 Output of pg_dumpall - ie dump of all PostgreSQL databases PostgreSQLdump_Bar.bz2 Dump of PostgreSQL database Bar if --separate-database. Directory specific backups, eg: etc.cpio.full.bz2 Full backup of /etc, this will have been done on a Monday. etc.cpio.incr.bz2 Incremental backup of /etc, all the files that have changed since the previous Monday. usr-local.cpio.full.bz2 Full backup of /usr/local, not how the '/' is replaced by a '-'. The symbolic links LATEST-FULL and LATEST-INCREMENTAL will be maintained to point to the directory that holds the appropriate successful backup. These directories will not be removed as a result of -c. LATEST-FULL is used with -d to determine what is incremental. Examples ******** BackupToDisk -b /arch/ -dc -D 'etc home root usr/local var/spool/cron var/www usr/share/wordpress' --mysql-dump --separate-database Put backup files under the directory /arch/ -- the file /arch/MOUNTED must exist. Perform a daily backup, cleaning out backups that are more than 2 weeks old. Backup files under the named directories: /etc /home /root ... Backup each MySQL database to a separate file. BackupToDisk --postgres-dump --postgres-user=postgres --postgres-host=/tmp --separate-database Backup PostgreSQL files as the user postgres, connect using a socket in /tmp/ Each database will be in a separate file. Restoring files *************** To list what is in an archive: bunzip2 -c /mnt/backup/daily/20071008/usr-local.cpio.full.bz2 | cpio -ivt Because there is a mixture of full and incremental files, you may need to restore the full backup and then the incremental on top of it. It is best to restore to a new directory and move over what you need: cd /usr/tmp bunzip2 -c /mnt/backup/daily/20071008/usr-local.cpio.full.bz2 | cpio -ivdum bunzip2 -c /mnt/backup/daily/20071010/usr-local.cpio.incr.bz2 | cpio -ivdum To selectively restore a whole directory: cd /usr/tmp bunzip2 -c /mnt/backup/daily/20071008/usr-local.cpio.full.bz2 | cpio -ivdum 'usr/local/bin/* bunzip2 -c /mnt/backup/daily/20071010/usr-local.cpio.incr.bz2 | cpio -ivdum 'usr/local/bin/* To selectively restore an individual file: cd /usr/tmp bunzip2 -c /mnt/backup/daily/20071008/usr-local.cpio.full.bz2 | cpio -ivdum usr/local/bin/BackupToDisk License ******* This software is copyright (c) Alain Williams , 1990 - 2014. This software is released under the GPL (version 2 or version 3). Contributing ************ BackupToDisk is free software (see the license). Free software grows and becomes more powerful and useful as those who gain by using it contribute their changes back to the original author. Contributions to this software are welcome. Please email the author the following: * your name & email address * your affiliation (company/institute/...) if any * the code * documentation * a statement that you are legally able to release the code and documentation * a statement transfering copyright to the Author below giving permission that it may be redistributed as part of UserAdmin under an appropriate license Contributions will be acknowledged in the Contributors file that accompanies this software. If you do not want to be acknowledged please make that clear. SCCS: @(#)README 1.13 08/13/14 17:31:21