Skip to content

Instantly share code, notes, and snippets.

@matteocaberlotto
Last active May 2, 2017 10:44
Show Gist options
  • Save matteocaberlotto/a27d35642d4cff39ca62 to your computer and use it in GitHub Desktop.
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)
#!/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