Created
August 11, 2014 11:07
-
-
Save bluegod/d0a5ce8eeb82475a843f to your computer and use it in GitHub Desktop.
Backron - filesystem/DB backup script. (old)
This file contains 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/sh | |
# Backron - Full and incremental backup script | |
# Based on a script by Daniel O'Callaghan <danny@freebsd.org> | |
# Done by James López (BLuEGoD) <bluegod at bluegod.net> | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# as published by the Free Software Foundation; either version 2 | |
# of the License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
# Full License text on: http://www.gnu.org/licenses/gpl-2.0.txt | |
# | |
# Backron version 1.2Beta - www.bluegod.net/backron | |
################################### | |
# Begin configuration | |
################################### | |
COMPUTER=mypc # name of this computer | |
# directories to backup: | |
DIRECTORIES="/usr/local/etc /etc /var/www" | |
XCLUDE="" # exclude FROM file (this file must | |
# contain the list of patterns, "" means nothing is exluded) | |
BACKUPDIR="/BACKUP" # where to store the backups | |
TAR=/usr/bin/tar # name and locaction of tar | |
# MySQL BACKUP | |
# Set this to one to enable MySQL BACKUP | |
DBBACKUP="1" | |
DBUSER="username" #MySQL user with full dump privileges | |
DBPASS="password" #MySQL user password | |
DBPATH="/usr/local/bin/mysqldump" | |
#path to mysqldump binary | |
DBOPS="-A" #mysqldump options -A means full dump | |
################################### | |
#You should not have to change anything below here | |
################################### | |
PATH=$PATH:/usr/local/bin:/usr/bin:/bin | |
DOW=`date +%a` # Day of the week e.g. Mon | |
DOM=`date +%d` # Date of the Month e.g. 27 | |
MY=`date +%b%y` # Month and year e.g. Sep08 | |
DD=`date +%a%d` # Date, month and year e.g. 27Sep08 | |
#xclude var to use with tar | |
if [ ! -z $XCLUDE ]; then | |
X="-X ${XCLUDE}" | |
fi | |
# On the 1st of the month the last weekly full backup is renamed so | |
# you will have every month only one backup / month saved. | |
# (previous weekly full backups will be deleted) | |
# Every Sunday a full backup is made (weekly full backup) not | |
# overwriting last weekly backups. | |
# The rest of the time an incremental backup is made. Each incremental | |
# backup overwrites last weeks incremental backup of the same name. | |
# NOTE: No incremental backup is made with MySQL dumps (full always) | |
# e.g. | |
# Using for 3 months this backup script since january you will have: | |
# January: PC-Jan08.tar.gz | |
# February: PC-Feb08.tar.gz | |
# March: PC-Dom01-FULL.tar.gz PC-Mon.tar.gz Pc-Tue.tar.gz ... | |
# Monthly full backup | |
if [ $DOM -eq "01" ]; then | |
#move last weekly full backup to be last month backup | |
find $BACKUPDIR -maxdepth 1 -mtime -7 -print -iname "*FULL*" -exec mv '{}' $BACKUPDIR/$COMPUTER-$MY.tar.gz \; >/dev/null | |
#then delete past weekly full backups | |
rm $BACKUPDIR/*FULL* >/dev/null | |
fi | |
#if mysql backup is turned on... | |
if [ $DBBACKUP -eq "1" ]; then | |
DBDB=$BACKUPDIR/SQLBACKUP.sql | |
$DBPATH $DBOPS -u $DBUSER -p$DBPASS >$DBDB | |
else | |
DBDB="" | |
fi | |
# Weekly full backup (also do it if this is the first time) | |
if [ $DOW = "Sun" ] || [ ! -f "$BACKUPDIR/.$COMPUTER-ful-date" ] | |
then | |
NOW=`date +%Y-%m-%d` | |
# Update full backup date | |
echo $NOW > $BACKUPDIR/.$COMPUTER-ful-date | |
#full backup, also with MySQL dumped DBs if $DBBACKUP=1 | |
$TAR $X -cPzf $BACKUPDIR/$COMPUTER-$DD-FULL.tar.gz $DIRECTORIES $DBDB | |
# Make incremental backup - overwrite last weeks | |
else | |
# Get date of last full backup | |
NEWER="--newer-mtime `cat $BACKUPDIR/.$COMPUTER-ful-date`" | |
$TAR $NEWER $X -cPzf $BACKUPDIR/$COMPUTER-$DOW.tar.gz $DIRECTORIES $DBDB | |
fi | |
if [ $DBBACKUP -eq "1" ]; then | |
rm $DBDB | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment