I created a automation bash script to upload backups to aws S3

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
Posts: 31
Joined: Wed Nov 26, 2014 12:42 am

I created a automation bash script to upload backups to aws S3

Postby BharathS » Wed Oct 11, 2017 4:21 pm

Hey All!,

After a long time of manually compressing, splitting and uploading zimbra backup to amazon s3 storage, I decided to automate this task with a simple bash script.

The script expects you to have configured s3cmd with your bucket details and secret key, then just edit out the script like destination path (local), bucket/folder name in S3, and finally put it on cron monthly, weekly however you want.

I have not added any condition or catches since I don't expect anything to change but send out an email notification at the start of upload and at the end of upload completion, this will give you an idea if the upload completion finished with a gap of hours or immediately in which case you'll have to check if its really working or not because of disk space issues, incorrect path etc.

Code: Select all

printuri=s3://bucket/Zimbrabackups/$(date +"%m-%d-%y")/Full/
cd /opt/zimbra/backup/sessions/
latestbackup=$(ls -td -- full* / | head -n 1)
echo $latestbackup
printf "${Green}Welcome!${NC}"
tar -czf /home/admin/upload/$latestbackup\.tar.gz $latestbackup
printf "${Green}Your backup has been successfully compressed!${NC}"
printf "${Green}Splitting your backup before preparing for Upload${NC}"
split -b 500MB /home/admin/upload/$latestbackup\.tar.gz /home/admin/upload/Full/$latestbackup\.tar.gz-
printf "${Green} Finished splitting!${NC}"
rm /home/admin/upload/$latestbackup\.tar.gz
printf "${Green}Uploading your files to Amazon S3 storage!${NC}"
echo "Subject: Begin Uploading Zimbra backup to AWS S3" | sendmail -v $alert
s3cmd put /home/admin/upload/Full/$latestbackup\.tar.gz-* $printuri
printf "${Greeen}Your backup has been uploaded to Amazon!${NC}"
rm -rf /home/admin/upload/Full/*
echo "Subject: Zimbra Backup Successfully Uploaded" | sendmail -v $alert

Return to “Administrators”

Who is online

Users browsing this forum: Baidu [Spider] and 28 guests