Skip to content

Instantly share code, notes, and snippets.

@avramovic
Created December 10, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avramovic/1fb7f82818628e43c881a596314e8769 to your computer and use it in GitHub Desktop.
Save avramovic/1fb7f82818628e43c881a596314e8769 to your computer and use it in GitHub Desktop.
Simple linux shell backup to s3 with s3cmd
#!/usr/bin/env bash
SQLDUMP="$1_db_$(date +'%Y%m%d%H%M').sql.gz"
echo "Creating backup of database to $SQLDUMP..."
/usr/bin/mysqldump --login-path=local --databases $1 | gzip -9 > $SQLDUMP
echo "Uploading zipped dump to the Amazon S3 bucket..."
/usr/bin/s3cmd put $SQLDUMP s3://your.s3.bucket.hostname/database/$SQLDUMP
echo "Removing the backup file $SQLDUMP"
rm $SQLDUMP
#!/usr/bin/env bash
BACKUPFILE="$1_files_$(date +'%Y%m%d%H%M').tar.gz"
echo "Creating backup of files to $BACKUPFILE..."
tar -zcvf $BACKUPFILE /home/$1/public_html/
echo "Uploading zipped dump to the Amazon S3 bucket..."
/usr/bin/s3cmd put $BACKUPFILE s3://your.s3.bucket.hostname/files/$BACKUPFILE
echo "Removing the backup file $SQLDUMP"
rm $BACKUPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment