This is a handy backup script that will once a week perform a vzdump operation on your HN, thus dumping an imaged copy of all of your virtual machines, then uploading them all to the FTP server of your choice using ncftpput.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #!/bin/bash # Container backup script ### System Setup ### BACKUP=/vz/backup.$$ NOW=$(date +"%Y-%m-%d") LAST=$(date +%Y-%m-%d -d '-7 days') DAY=$(date +"%a") HOSTNAME="$(hostname)" DUMP="$(which vzdump)" ### FTP server Setup ### FTPD="/backups" FTPU="username" FTPP="password" FTPS="xxx.xxx.xxx.xxx" NCFTP="$(which ncftp)" ### Other stuff ### EMAILID="support@hostname.com" ### Start Backup for file system ### [ ! -d $BACKUP ] && mkdir -p $BACKUP || : $DUMP --exclude-path '.+/log/.+' --exclude-path '.+/bak/.+' --exclude-path '/tmp/.+' --exclude-path '/var/tmp/.+' --exclude-path '/var/run/.+pid' --stop --dumpdir=$BACKUP --compress --all ### Dump backup using FTP ### #Start FTP backup using ncftp $NCFTP -u"$FTPU" -p"$FTPP" $FTPS < < EOF mkdir $FTPD/$NOW cd $FTPD/$NOW lcd $BACKUP mput * rmdir $FTPD/$LAST quit EOF ### Find out if ftp backup failed or not ### if [ "$?" == "0" ]; then rm -rf $BACKUP else T=/tmp/backup.fail echo "Date: $(date)">$T echo "Hostname: $(hostname)" >>$T echo "Backup failed" >>$T mail -s "BACKUP FAILED" "$EMAILID" < $T rm -rf $T fi |
0 Responses to “OpenVZ Container Weekly Bash Backup Script: VZDUMP”