On Saturday 30 August 2003 10:51 pm, Ernie Schroder wrote: > > Thanks much, that seems to have done the trick! the script is > building a file list now. Providing the backup is successful, I will > post it to the list for archive purposes.
the backup was successful. here is my script, I hope others can take advantage of it. It performs a backup via rsync and ssh from the local machine to a dedicated disk on a remote machine. You will need to establish passwordless ssh between the root accounts of both machines in order for it to run unattended as in a cron job. see: http://pigtail.net/LRP/printsrv/keygen.html for a good howto. the script: #====================================================================== #! /bin/bash # /usr/local/bin/my-rsync ####################### # Backup Script ####################### [EMAIL PROTECTED]:/mnt/backup #path to backup disk EXCLUDE=/usr/local/bin/rsync-exclude #list of files and #directories to be excluded echo " Mounting boot partition..." sudo mount /boot -o ro echo echo " Mounting backup disk..." ssh [EMAIL PROTECTED] <<END sleep 5 #adjust as needed to establish connection mount /dev/hdb1 /mnt/backup #note that I have no fstab entry for #/mnt/backup on the remote box. If you do, this line would read: #mount /mnt/backup END sleep 4 # gives disk time to spin up echo echo " Performing backup..." echo rsync --rsh="ssh" --progress --delete -av --exclude-from=$EXCLUDE / \ $BACKUP_TO/rsync/ #rsync's local machine to remote #/mnt/backup/rsync and deletes files from backup that have been deleted #from the local machine. You might want to consider changing this. echo echo " Unmounting boot and backup partitions..." /bin/umount -l /boot ssh [EMAIL PROTECTED] <<END sleep 5 umount /mnt/backup echo echo " Spinning down backup disk..." /sbin/hdparm -y /dev/hdb # spin down disk (assumes that #hdparm is installed) END #====================================================================== As Peter Ruskin said in his discussion earlier in this thread, this will take quite a while the first time. It took about 12 hours over my 10base network to backup 6.5 Gigs. The second run, after deleting some files from /home/USER and modifying a few large ones to test the script took about 15 minutes, again mostly due to slow networking. You will need to save the script to /usr/local/bin/my-rsync and mqke it executable: # chmod a+x /usr/local/bin/my-rsync You will also need to make a file: /usr/local/bin/rsync-exclude This file contains a list of files and directories that you don't want backed up. (Your porn movies for example if you're backing up to a disk on your son's machine) Here's mine: # /usr/local/bin/rsync-exclude: - /tmp/ - /var/lib/init.d/ - /mnt/flash - /mnt/smartcard - /mnt/tmp - /mnt/cdrom/ - /mnt/cdrom1/ - /mnt/floppy/ - /proc/ - /usr/portage/distfiles/ - /home/ernie/Shared_Music - /home/ernie/tmp #Add what ever you won't need or can't fit #depending on available disk space I'll add Peter's comments here: ____________________________________________________________ As Andrew Farmer suggested, you can use /etc/cron.daily to have it run automatically. Before you do so, run it manually to make sure it works for you, altering the mountpoint ($BACKUP_TO) and /dev/hdc in the "spin down disk" part to suit your installation. My /etc/fstab entry for $BACKUP_TO reads: /dev/hdc1 /mnt/backup ext3 noauto,noatime,users 0 0 ...so, like /boot, it's only mounted when needed. When you are ready to add the backup script to cron.daily, become root and do: cp /usr/local/bin/my-rsync /etc/cron.daily/ ____________________________________________________________ My thanks to Peter Ruskin for the basis of the script, Andrew Farmer for the cron suggestion and Jussi Sirpoma for his help debugging. -- Regards, Ernie 100% Microsoft and Intel free -- [EMAIL PROTECTED] mailing list
