Created
January 21, 2021 02:08
-
-
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
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 | |
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