Skip to content

Instantly share code, notes, and snippets.

@michaelaguiar
Last active January 4, 2019 20:06
Show Gist options
  • Save michaelaguiar/10754834 to your computer and use it in GitHub Desktop.
Save michaelaguiar/10754834 to your computer and use it in GitHub Desktop.
Compress site and database for backup
#!/bin/bash
# Set Timestamp
time_stamp=$(date +%Y-%m-%d)
# Create Backup Directory
mkdir /backups/$time_stamp
# Backup Database
mysqldump -u root --password=DB_PASS --all-databases | gzip > /PATH/TO/SQL_DUMP.sql.gz
# Backup the web directory
echo 'Backing up files...';
tar -czf /backups/$time_stamp/$time_stamp-backup.tar.gz /home >/dev/null 2>&1
# Upload to Google Cloud Storage
echo 'Uploading to Cloud Storage...';
gsutil cp -r /backups/$time_stamp/ gs://BUCKET_PATH/ >/dev/null 2>&1
# Cleanup
echo 'Cleaning Up...';
rm -r /backups/$time_stamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment