Skip to content

Instantly share code, notes, and snippets.

@anil3a
Created January 21, 2021 02:08
Show Gist options
  • Save anil3a/279191006d6f39cfd238d858339cd657 to your computer and use it in GitHub Desktop.
Save anil3a/279191006d6f39cfd238d858339cd657 to your computer and use it in GitHub Desktop.
Create Database backup script and check file is older than 10 days if yes delete
#!/bin/bash
MY_HOME="/var/www/prajapatianil.com.np/backupdb/"
case $1 in
"backup")
cd $MY_HOME
mysqldump -h localhost -u 'usermysql' -p'passwordmysql' databasename > websitedb$(date +%Y%m%d_%H).sql
tar -zcvf websitedb$(date +%Y%m%d_%H).tgz websitedb$(date +%Y%m%d_%H).sql
rm websitedb$(date +%Y%m%d_%H).sql;;
*) echo "Others";;
esac
# Delete file older than 10 days
find /var/www/prajapatianil.com.np/backupdb/ -mtime +10 -type f -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment