Last active
August 23, 2022 19:18
-
-
Save morshadunnur/33b2945749388e813dfab7070c090dda to your computer and use it in GitHub Desktop.
Backup database and find 3 days old files and delete old files
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 | |
BACKUPDIR="/directory_path" | |
# assuming that /nas is mounted via /etc/fstab | |
if [ ! -d $BACKUPDIR ]; then | |
mkdir -p $BACKUPDIR | |
else | |
: | |
fi | |
DBNAME="dbname" | |
DBUSERNAME="root" | |
DBPASSWORD="12345678" | |
mysqldump -u $DBUSERNAME -p$DBPASSWORD $DBNAME > $BACKUPDIR/backup_$(date +"%Y_%m_%d_%I_%M_%p").sql | |
# find and delete 3 days old files | |
find $BACKUPDIR/ -type f -mtime +3 -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment