Skip to content

Instantly share code, notes, and snippets.

@asmt3
Created November 16, 2016 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmt3/790c49470e89eddff7667d12e015b67d to your computer and use it in GitHub Desktop.
Save asmt3/790c49470e89eddff7667d12e015b67d to your computer and use it in GitHub Desktop.
Script to do regular MySQL backup on TSO Hosts
#!/bin/bash
#Database login credentials - need to be changed accordingly
dbHost="***"
dbName="**"
dbUser="***"
dbPass="***"
#How many days the backups should be kept for before being removed
keepBackupsFor="30"
if [ ! -d ~/additional_backups ]; then mkdir ~/additional_backups; fi
curTime=$(date +"%m-%d-%y_%H:%M")
mysqldump -h ${dbHost} -u ${dbUser} -p${dbPass} ${dbName} > ~/additional_backups/${curTime}-sql_backup.sql
find ~/additional_backups -type f -ctime +${keepBackupsFor} -exec rm -f {} \;
@chrishow
Copy link

Crikey, that's disturbingly simple.

I love it!

Thanks a bunch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment