Skip to content

Instantly share code, notes, and snippets.

@mattmezza
Last active September 28, 2018 06:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mattmezza/d2b868ce51030c9b908b to your computer and use it in GitHub Desktop.
Save mattmezza/d2b868ce51030c9b908b to your computer and use it in GitHub Desktop.
Super Simple Backup System, a very simple system to automatically backup mysql and ftp.
#!/bin/bash
OUTDIR=$1
BACKUP=$OUTDIR/tmp
NOW=$(date +"%d-%m-%Y")
# clean up tmp dir
rm -f -r $BACKUP/*
# backup a folder of a website
FILE=fs-rootfolder-full.$NOW
mkdir $BACKUP/$FILE
wget -P $BACKUP/$FILE -m --user yourftpusername --password "yourftppassword" ftp://hostname.tld/webfolder/ && tar cvzf $OUTDIR/ftp/$FILE.tar.gz $BACKUP/$FILE
# backup another folder of a website
# FILE=fs-another_folder-full.$NOW
# mkdir $BACKUP/$FILE
# wget -P $BACKUP/$FILE -m --user yourftpusername --password "yourftppassword" ftp://hostname.tld/anotherfolder/ && tar cvzf $OUTDIR/ftp/$FILE.tar.gz $BACKUP/$FILE
# remove old backup
# retention is set to 9 days
find $OUTDIR/ftp/ -mtime +9 -exec rm {} \;
# clean up tmp dir
rm -f -r $BACKUP/*
#!/bin/bash
OUTDIR=$1
NOW=$(date +"%d-%m-%Y")
# mysql backup of a db
FILE=mysql-dbname.$NOW-$(date +"%T").sql
mysqldump -h hostname.tld -u mysql_user -pmysqlpassword --opt dbname > $OUTDIR/mysql/$FILE
tar cvzf $OUTDIR/mysql/$FILE.tar.gz $OUTDIR/mysql/$FILE
rm $OUTDIR/mysql/$FILE
# mysql backup of another db
# FILE=mysql-anotherdbname.$NOW-$(date +"%T").sql
# mysqldump -h hostname.tld -u mysql_user -pmysqlpassword --opt anotherdbname > $OUTDIR/mysql/$FILE
# tar cvzf $OUTDIR/mysql/$FILE.tar.gz $OUTDIR/mysql/$FILE
# rm $OUTDIR/mysql/$FILE
# remove old backup
# retention is set to 15 days
find $OUTDIR/mysql/* -mtime +15 -exec rm {} \;
@mattmezza
Copy link
Author

mattmezza commented Dec 11, 2014

You can read this blog post to understand how to use these files.

Cheers!

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