Last active
January 4, 2019 20:06
-
-
Save michaelaguiar/10754834 to your computer and use it in GitHub Desktop.
Compress site and database for backup
This file contains hidden or 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 | |
# 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