docs:programming:shell_scripting:backup_rsync

Backup rsync scripts

backup_rsync_programming.sh

#!/bin/sh

~/scripts/backup/rsync/backup_rsync.sh --users-billh-prog-only

exit 0

backup_rsync.sh

#!/bin/bash

a=/Volumes/Seagate-1
b=/Backup_rsync
y=$a$b

# if the drive mount doesn't exist, then exit with an error
if [ ! -d $a ];then
	echo -e "Error:\n\tThe drive mount point $a$b\n\tcould not be found.  Maybe the drive is unplugged, or the power is off."
	exit 1
fi

#read -p "sleep after backup? (y/n)> " input

echo -e "backup started at: $(date '+%F %T')\n"

if [ -z $1 ] || [ $1 == "--etc-only" ];then
	echo -e "/etc/...\n\
		CiscoSystemsVPNClient/*\n\
		httpd/*\n\
		anacrontab\n\
		bashrc\n\
		crontab\n\
		efax.rc\n\
		hostconfig\n\
		hosts*\n\
		motd*\n\
		php.ini*\n\
		profile*\n\
		smb.conf*\n\
		ssh_config\n\
		sshd_config"
	rsync -aR --delete-excluded --delete-after /private/etc/CiscoSystemsVPNClient "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/httpd "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/anacrontab "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/bashrc "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/crontab "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/efax.rc "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/hostconfig "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/hosts* "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/motd* "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/php.ini* "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/profile* "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/smb.conf* "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/ssh_config "$y"
	rsync -aR --delete-excluded --delete-after /private/etc/sshd_config "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--applications-only" ];then
	echo -e "/Applications/...\n\
		iSync.app"
	rsync -aR --delete-excluded --delete-after /Applications/iSync.app "$y"	
	echo -e "\tDone\n"
fi

#if [ -z $1 ] || [ $1 == "--sw-var-mysql-only" ];then
#	echo "/sw/var/mysql/ hartung,azparcels, and ticketdb"
#	rsync -aR --delete-excluded --delete-after /sw/var/mysql/hartung "$y"
#	rsync -aR --delete-excluded --delete-after /sw/var/mysql/azparcels "$y"
#	rsync -aR --delete-excluded --delete-after /sw/var/mysql/ticketdb "$y"
#	echo -e "\tDone\n"
#fi

#if [ -z $1 ] || [ $1 == "--sw-etc-only" ];then
#	echo "/sw/etc"
#	rsync -aR --delete-excluded --delete-after --exclude "/sw/etc/openldap*" /sw/etc "$y"
#	echo -e "\tDone\n"
#fi

if [ -z $1 ] || [ $1 == "--sw-only" ];then
	echo "/sw"
	rsync -aR --delete-excluded --delete-after --exclude "/sw/var/apache2/logs/cgisock" /sw "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-websites-only" ];then
	echo "/Public/Web Sites"
	rsync -aR --delete-excluded --delete-after /Public/Web\ Sites "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--users-billh-only" ];then
	echo "/Users/billh"
	rsync -aR --delete-excluded --delete-after --exclude "/Users/billh/Applications/*" --exclude "/Users/billh/.qt/*" --exclude "/Users/billh/Library/Acrobat User Data/8.0_ppc/Synchronizer/*" /Users/billh "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--users-shared-only" ];then
	echo "/Users/Shared"
	rsync -aR --delete-excluded --delete-after /Users/Shared "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-drawings-only" ];then
	echo "/Public/Drawings"
	rsync -aR --delete-excluded --delete-after /Public/Drawings "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-work-only" ];then
	echo "/Public/Work"
	rsync -aR --delete-excluded --delete-after /Public/Work "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-graphics-only" ];then
	echo "/Public/Graphics"
	rsync -aR --delete-excluded --delete-after /Public/Graphics "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-books-only" ];then
	echo "/Public/Books"
	rsync -aR --delete-excluded --delete-after /Public/Books "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-downloads-only" ];then
	echo "/Public/Downloads"
	rsync -aR --delete-excluded --delete-after /Public/Downloads "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-emulation-only" ];then
	echo "/Public/Emulation"
	rsync -aR --delete-excluded --delete-after /Public/Emulation "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-miscassets-only" ];then
	echo "/Public/_MISC_ASSETS"
	rsync -aR --delete-excluded --delete-after /Public/_MISC_ASSETS "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-zipdisks-only" ];then
	echo "/Public/Zip Disks"
	rsync -aR --delete-excluded --delete-after /Public/Zip\ Disks "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--system-library-startupitems-only" ];then
	echo "/System/Library/StartupItems"
	rsync -aR --delete-excluded --delete-after /System/Library/StartupItems "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-pictures-only" ];then
	echo "/Public/Pictures"
	rsync -aR --delete-excluded --delete-after --exclude "*.CRW.preview" --exclude "*.crw.preview" /Public/Pictures "$y"
	echo -e "\tDone\n"
fi

if [ -z $1 ] || [ $1 == "--public-music-only" ];then
	echo "/Public/Music"
	rsync -aR --delete-excluded --delete-after /Public/Music "$y"
	echo -e "\tDone\n"
fi

# the backups below are special cases, and aren't processed without their specific argument
# $1 is quoted to avoid the "unary operator expected" error
if  [ "$1" == "--all-websites" ];then
	echo "/Public/Web Sites"
	rsync -aR --delete-excluded --delete-after /Public/Web\ Sites "$y"
	echo -e "\tDone\n"
	
	echo "/Users/billh/Sites"
	rsync -aR --delete-excluded --delete-after /Users/billh/Sites "$y"
	echo -e "\tDone\n"
	
	echo "/Public/Work/web sites"
	rsync -aR --delete-excluded --delete-after /Public/Work/web\ sites "$y"
	echo -e "\tDone\n"
fi

if  [ "$1" == "--users-billh-prog-only" ];then
	echo "/Users/billh/prog"
	rsync -aR --delete-excluded --delete-after /Users/billh/prog "$y"
	echo -e "\tDone\n"
fi

echo -e "backup finished at: $(date '+%F %T')\n"

# should the computer be put to sleep after the script is finished?
#if [ "$input" == "y" ]; then
#	sleep 10
#	~/scripts/SleepNow
#fi

exit 0

Modify the beginning of the file to create/update a directory with a date

  • rsync_snapshot/backup_rsync.sh
#!/bin/bash

a=/Volumes/Seagate-1
b="/Backup_rsync_snapshot_$(date '+%F')"
y=$a$b

(continue with main script)
...
  • docs/programming/shell_scripting/backup_rsync.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1