Skip to content

Instantly share code, notes, and snippets.

@maztch
Created November 16, 2016 12:51
Show Gist options
  • Save maztch/fcb1404b11316415cd94d214cb5f1cba to your computer and use it in GitHub Desktop.
Save maztch/fcb1404b11316415cd94d214cb5f1cba to your computer and use it in GitHub Desktop.
database backup script
#!/bin/bash
# this script makes a database backup and delete files older than 15 days
# to make script execuable use 'chmod +x backupdb.sh'
# change username, password and database for yours and modify your path if needed
mysqldump -u [username] -p[password] [database_name] > /root/backups/db_backup_`date +"%Y%m%d%H%M%S"`.sql
# change '-mtime +15' to keep more or less days (and path if needed)
find /root/backups/* -mtime +15 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment