-
-
Save johanneslamers/62c8d4ff9eb76e368fe41d63032fb7c7 to your computer and use it in GitHub Desktop.
S3 backup for ServerPilot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export BUCKET=filament-sp-backup | |
date_daily=`date +"%Y-%m-%d"` | |
tmp_dir=/tmp/sp-backup-$date_daily | |
# Get current month and week day number | |
month_day=`date +"%d"` | |
week_day=`date +"%u"` | |
# On first month day do | |
if [ "$month_day" -eq 1 ] ; then | |
destination=$tmp_dir/monthly/`hostname`/$date_daily | |
type="monthly" | |
else | |
# On saturdays do | |
if [ "$week_day" -eq 6 ] ; then | |
destination=$tmp_dir/weekly/`hostname`/$date_daily | |
type="weekly" | |
else | |
# On any regular day do | |
destination=$tmp_dir/daily/`hostname`/$date_daily | |
type="daily" | |
fi | |
fi | |
rm -fr $tmp_dir/* | |
db_destination=db/`hostname`/ | |
echo $db_destination | |
s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/$db_destination | |
shopt -s dotglob | |
find /srv/users/* -prune -type d | while read d; do | |
user=$(basename "$d") | |
find $d/apps/* -prune -type d | while read e; do | |
app=$(basename "$e") | |
# skip daily dev site backups | |
if ([[ "$app" =~ ^(dev|staging|proto) ]] || [[ "$app" =~ (dev|staging|proto)$ ]]) && [[ "$type" == "daily" ]] ; then | |
continue | |
fi | |
cd $d/apps | |
mkdir -p $destination/$user/apps | |
archive=$destination/$user/apps/$app.tgz | |
echo "$e => $archive" | |
tar cvzfp $archive $e | |
done | |
done | |
find /etc/apache-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $destination/sp-config.tar {} \; | |
find /etc/nginx-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $destination/sp-config.tar {} \; | |
find /etc/nginx-sp/ssl/ -type f -exec tar -rvf $destination/sp-config.tar {} \; | |
s3cmd put --recursive $tmp_dir/* s3://$BUCKET/ | |
rm -fr $tmp_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment