Last active
May 2, 2017 10:44
-
-
Save matteocaberlotto/a27d35642d4cff39ca62 to your computer and use it in GitHub Desktop.
Dumps a mysql database daily at midnight (with day of the week rotation)
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 | |
_dow="$(date +'%A'|cut -c 1-3)" | |
# dumps the database with day of the week appended | |
mysqldump mydb -u db-user -p'password' > "/home/ubuntu/databases/database-demo-${_dow,,}.sql" | |
# copies last db dumped | |
cp "/home/ubuntu/databases/database-demo-${_dow,,}.sql" /home/ubuntu/database-demo.sql | |
cd /var/www/example/current/web | |
# publishes sql file | |
if [ ! -f "database-demo.sql" ]; then | |
ln -s /home/ubuntu/database-demo.sql | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment