Last active
September 28, 2018 06:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 {} \; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can read this blog post to understand how to use these files.
Cheers!