From: Joe Z. <jz...@us...> - 2005-01-23 20:03:27
|
Update of /cvsroot/bobs/bobs/inc/templates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18042/inc/templates Added Files: backup_rsync_ssh.sh backup_smb.sh Removed Files: backup_smb_backup_files.sh backup_smb_mount_server.sh backup_smb_unmount_server.sh Log Message: Add completion status messages to bobs.log and optional email. --- NEW FILE: backup_rsync_ssh.sh --- #!/bin/bash # Description: Backup files using rsync over secure shell (ssh) # # options used for rsync # --archive = archive mode # --verbose = verbose execution # --delete = delete files from backup when deleted on the original site # --backup = make backups # --backup-dir=DIR = move backups into this dir # --exclude-from=FILE = exclude files listed in this file ############################################################################# # email backup completion status # $1 = subject # $2 = body ############################################################################# email(){ if [ -z "{EMAILADDR}" ]; then return; fi echo "$2" | mail -s "$1" {EMAILADDR} } ############################################################################# # Put message in bobs status window ############################################################################# shstats(){ echo "{SESSION_ID}.$1" >> "{SHSTATS}" } ############################################################################# # error routine ############################################################################# error() { if [ -z "$2" ]; then LONGMSG="$1"; else LONGMSG="$2"; fi # This messages shows on the bob restore status window shstats "$1" # This message goes into bobs.log echo "BACKUP FAILED for {SERVER} / {SHARE}. $LONGMSG" email "BACKUP FAILED for {SERVER} / {SHARE}" "$LONGMSG" } ############################################################################# # Mainline ############################################################################# shstats "Running backup" echo "Starting backup of {SERVER} / {SHARE}" rsync -e ssh --archive --verbose --delete --backup --compress \ {EXCLUDE_FROM} \ --backup-dir="{INCOMINGDIR}/{SERVER}/{SHARE}/" \ {RSYNC_SSH_USER}@{SERVER_NAME_OR_IP}:{RSYNC_SSH_PATH} \ "{BACKUPDIR}/{SERVER}/{SHARE}/" RC=$? if [ $RC -ne 0 ]; then error "Backup failed" \ "Backup failed with return code $RC. See bobs.log for details." else shstats "Backup successful" echo "Backup successful for {SERVER} / {SHARE}." email "Backup successful for {SERVER} / {SHARE}." "This is a good thing." fi exit 0 # END --- NEW FILE: backup_smb.sh --- #!/bin/bash # Description: Backup files from an smb share ############################################################################# # email backup completion status # $1 = subject # $2 = body ############################################################################# email(){ if [ -z "{EMAILADDR}" ]; then return; fi echo "$2" | mail -s "$1" {EMAILADDR} } ############################################################################# # Put message in bobs status window ############################################################################# shstats(){ echo "{SESSION_ID}.$1" >> "{SHSTATS}" } ############################################################################# # error routine ############################################################################# error() { if [ -z "$2" ]; then LONGMSG="$1"; else LONGMSG="$2"; fi # This messages shows on the bob restore status window shstats "$1" # This message goes into bobs.log echo "BACKUP FAILED for {SERVER} / {SHARE}. $LONGMSG" email "BACKUP FAILED for {SERVER} / {SHARE}" "$LONGMSG" } ############################################################################# # Mainline ############################################################################# # Mount the smb share shstats "Mounting smb share" if [ ! -d "{MOUNTDIR}" ]; then mkdir -p "{MOUNTDIR}" || { error "mkdir failed (mount)" "Error creating mount directory." exit 1 } fi mount -t smbfs -o username={LOGIN},password={PASSWORD} \ //{SERVER_NAME_OR_IP}/{SMB_SHARE} {MOUNTDIR} RC=$? if [ $RC -ne 0 ]; then error "Mount failed" "Samba mount failed with return code $RC. See bobs.log for details." exit 1 fi shstats "Mounted smb share" # backup files from the smb share shstats "Running backup" echo "Starting backup of {SERVER} / {SHARE}" rsync --archive --verbose --delete --backup --compress \ --backup-dir="{INCOMINGDIR}/{SERVER}/{SHARE}/" \ {EXCLUDE_FROM} \ "{MOUNTDIR}/" "{BACKUPDIR}/{SERVER}/{SHARE}/" RC=$? if [ $RC -ne 0 ]; then error "Backup failed" \ "Backup failed with return code $RC. See bobs.log for details." else shstats "Backup successful" echo "Backup successful for {SERVER} / {SHARE}." email "Backup successful for {SERVER} / {SHARE}." "This is a good thing." fi # unmount the samba share umount "{MOUNTDIR}" if [ $? -ne 0 ]; then error "Unmount failed" \ "Error occured while trying to unmount samba directory {MOUNTDIR}. See bobs.log for details." else shstats "Unmounted smb share" fi exit 0 # END --- backup_smb_backup_files.sh DELETED --- --- backup_smb_mount_server.sh DELETED --- --- backup_smb_unmount_server.sh DELETED --- |