Skip to content

Instantly share code, notes, and snippets.

@i-sync
Last active November 19, 2018 05:58
Show Gist options
  • Select an option

  • Save i-sync/7f442841e8e44dd6627631e92a558a8f to your computer and use it in GitHub Desktop.

Select an option

Save i-sync/7f442841e8e44dd6627631e92a558a8f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Database credentials
user="xxx"
password="xxx"
host="xxx"
db_name="xxxx"
# Other options
backup_path="/data/backup/mysql"
d=$(date +"%F-%T")
# Set default file permissions
umask 177
# Dump database into SQL file
mysqldump --user=$user --password=$password $db_name > $backup_path/$db_name-$d.sql
# Delete files older than 30 days
find $backup_path/* -mtime +30 -exec rm {} \;
#scp to remote server
sshpass -p "xxxx" scp $backup_path/$db_name-$d.sql xxx@domain.com:/path/backup/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment