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.
BharathS
Posts: 29
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

#!/bin/bash
Green='\033[0;32m'
NC='\033[0m'
alert="yourname@company.com"
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}"
echo
echo
echo
tar -czf /home/admin/upload/$latestbackup\.tar.gz $latestbackup
printf "${Green}Your backup has been successfully compressed!${NC}"
echo
printf "${Green}Splitting your backup before preparing for Upload${NC}"
echo
split -b 500MB /home/admin/upload/$latestbackup\.tar.gz /home/admin/upload/Full/$latestbackup\.tar.gz-
echo
printf "${Green} Finished splitting!${NC}"
rm /home/admin/upload/$latestbackup\.tar.gz
echo
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
echo
printf "${Greeen}Your backup has been uploaded to Amazon!${NC}"
echo
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: No registered users and 69 guests