Last active
March 24, 2020 06:01
-
-
Save amitavroy/c293481479b31aea31a8b6eed986ed8e to your computer and use it in GitHub Desktop.
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 | |
# declare an array called array and define 3 vales | |
databases=( drupal fresh lasalle_wp_fts ) | |
username=root | |
password=password | |
filepath=/home/amitavroy/code/backup | |
for i in "${databases[@]}" | |
do | |
filename=${i}_$(date +"%m%d%Y-%k%M") | |
mysqldump -u${username} -p${password} ${i} > ${filepath}/${filename}.sql | |
tar -zcf ${filepath}/${filename}.tar.gz ${filepath}/${filename}.sql | |
rm ${filepath}/${filename}.sql | |
done |
Shell script to delete DB backup older than 2 days
Crontab command to run at 5pm everyday => 0 17 * * * /home/fwdev/remove_backup_files.sh
#!/bin/bash
databases=(lasalle_gj_drupal)
filepath=/home/fwdev/lasalle_gj_db_backups
for i in "${databases[@]}"
do
filename=${filepath}/${i}_$(date -d "-2 days" +"%m%d%Y")
rm ${filename}*
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changed the file. All the folder reference should be absolute.