What is this about ? ******************** This script helps to copy a backup created by RsyncBackup to a USB attached disk drive. This is an interactive script designed to be used by an end user, it can also be run non interactively from cron. The user will be required to login to the machine (ssh or putty) and type one command: UsbBackup and then follow the prompts that allow: * removal of old archives (should the disk be getting full); * selection of which machines' backups to copy to the USB drive. The USB drive should be formatted as a file system (eg ext3). The archives are written to the drive as gzipped tar files (other options). This is designed to be used in conjunction with RsyncBackup which will have created a backup of (remote) machines to an archive partition on the local machine. The sort of directory layout that UsbBackup expects is something like this: /arch/ drwxr-xr-x. 5 root root 4096 Jan 10 06:00 backup drwxr-xr-x. 10 root root 4096 Jan 10 06:08 server /arch/backup/ drwxr-xr-x. 7 root root 4096 Jan 9 20:18 20120109 drwxr-xr-x. 7 root root 4096 Jan 10 06:00 20120110 lrwxrwxrwx. 1 root root 8 Jan 10 06:00 LATEST -> 20120110 drwxr-xr-x. 2 root root 4096 Jan 9 20:19 Totals You may want to make this automatically invoked from a user's .profile or .bash_profile Installation ************ Copy the file UsbBackup 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. The script backup should also be copied to /usr/local/bin and made executable. You may need to tweak it -- device name or mount point, logfile. This is the script that you tell the end user to run, ie they just type: backup Edit /etc/sudoers with something like that below. Substitute appropriate user names and machine name: User_Alias BACKUP_ADMINS = john, addw BACKUP_ADMINS archive.example.co.uk = NOPASSWD:/usr/local/bin/UsbBackup Run from .profile ***************** Include at the end of the .profile or .bash_profile for the user backup: # Stop them breaking out: trap exit 2 3 stty intr ^- quit ^- susp ^- sudo /usr/local/bin/RunUsbBackup sleep 3 # Alow messages to be seen exit /usr/local/bin/RunUsbBackup runs UsbBackup with parameters as needed locally, eg: #!/bin/ksh -u exec /usr/local/bin/UsbBackup -D /media/backup --nodev In /etc/sudoers you would have: backup ALL =(ALL) NOPASSWD:/usr/local/bin/RunUsbBackup Run from Cron ************* The key here is running it on a day/time when the USB disk will be installed in the machine. In the example below runs it at 10am on a Wednesday, the idea being that the disk can be inserted first thing in the morning. If doing weekly backup do not choose a Monday since these are, occasionally, public holidays. The, unsupported, helper script NotifyBackupDisk is run the day before to check that the expected USB disk is attached and mounted. This script is installed in the documentation directory, you may well need to hack it to your taste. 0 10 * * 3 UsbBackup --machines='backup server1 server2' --auto --mount=/media/backup/ --gzip -M usbbackup@localhost --nodev --label-log-line1 --copy-label=/root/LastBackupLabel --ensure-free=20 0 10 * * 2 NotifyBackupDisk This relies on a label file, what this looks like is described in NotifyBackupDisk. Preparation of the USB disk *************************** Plug the disk in, it will become available as /dev/sda or similar. Partition the disk with fdisk: fdisk /dev/sda Create a partition '1' - /dev/sda1, make it type 83 (Linux). Format. Since the disk will contain a small number of very large files you may want to reduce the number of inodes on the disk (-N option, 1 million is still probably far too many): mkfs.ext3 /dev/sda1 or mke2fs -j /dev/sda1 or mke2fs -t ext4 -N 1000000 /dev/sda1 Create the file BackupDisk in the root of the file system. This file is checked for by the script ... if it doesn't exist, an error is assumed. Something like: mount /dev/sda1 /media/usbdisk touch /media/usbdisk/BackupDisk umount /media/usbdisk (You may want to put some message in the file BackupDisk, if it is non zero in size the file will be output to the program log - see --label-line1. You may also want to have this file copied when the program starts - see --copy-label, this could be useful in analysing which disks are used or what disk to use next.) When a disk is mounted there may be checks on how long since the last fsck or how many times it has been mounted. You may want to tweak the number of mounts, or the interval, with a command like: tune2fs -i 0 -c 0 /dev/sda1 To cause it to be mounted at /media/usbdisk this may work: e2label /dev/sda1 usbdisk (Depends on how your system is configured) You may put a short description into the BackupDisk file, this will be printed in some of the log messages: echo 'Backup disk A for server, first used March 2012' > /media/usbdisk/BackupDisk You may need to put more in it if you use NotifyBackupDisk, see above. Options ******* --auto Automatic mode, non-interactive, do not prompt the user --copy-label=file Copy the disk label file (BackupDisk) to the names filefile. -d dev Device name on which the USB device appears, default /dev/sda1 -D dir --mount=dir Directory where the USB device will be mounted, default /media/usbdisk --ensure-free=percent Before starting an --auto backup ensure that there is at least percent% free space on the removable disk. The LATEST backup will not be removed. If percent% free cannot be achieved the backup is aborted. -j, --bzip2 Use bzip2 to compress the output tar files, this is the default -l Local directory where the backups are found, default /arch -L file Log file - default /var/log/UsbBackup --label-log-line1=n Only log the first line of the label file - default log the entire file. If the optional argument 'n' is given, log that number of lines. -m Machines to show to the user. You may use this to limit the machines seen by a user. If this is not given a list of names is taken from what is found under /arch (lost+found will be ignored). -M addr Mail a success/fail message to addr, space separated list. May be given more than once. --nodev If you have labeled the disks with e2label so that it is automounted then you may not care what physical device it appears as. This option prevents UsbBackup from trying to look for a physical device -- but will fail if the disk does not appear at /media/usbdisk --no-compress Do not compress the output tar files --no-space-check Don't check for enough free space before attempting to copy each machine's backup -q --quiet Quiet mode -v Verbose mode -x --help eXplain -- give a help message. -z, --gzip Use gzip to compress the output tar files License ******* This software is copyright (c) Alain Williams , 2006. This software is released under the GPLv3, see: http://www.gnu.org/licenses/gpl-3.0.html Keeping up to date ****************** You may find newer versions of this software at: http://www.phcomp.co.uk/downloads.php Where you will also find references to email lists that relate to this software. Contributing ************ UsbBackup 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. The author will be pleased to receive your comments, good or bad. SCCS: @(#)README 1.9 10/15/12 13:45:20