Skip to content

Instantly share code, notes, and snippets.

@morshadunnur
Last active August 23, 2022 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morshadunnur/33b2945749388e813dfab7070c090dda to your computer and use it in GitHub Desktop.
Save morshadunnur/33b2945749388e813dfab7070c090dda to your computer and use it in GitHub Desktop.
Backup database and find 3 days old files and delete old files
#!/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