Files
incremental-backup/bak-pars.sh

69 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
########################################################################
# Copyright (C) 2015 Max Mehl <mail@mehl.mx>
########################################################################
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
########################################################################
#
# Einfaches Shellscript zum inkrementellen Sichern von Verzeichnissen und Dateien
# Dieses Script liest mitgegebene Parameter aus und bietet keinen Prompt
# Basiert auf dem Backupscript von Max Kalus:
# http://www.auxnet.de/blog/blog-post/2008/10/27/taegliches-inkrementelles-backup-mit-cron-und-tar-unter-linux.html
#
########################################################################
# Festgelegte Variablen, müssen nicht geändert werden
LASTMONTHDIR=lastmonth
TSNAME=timestamp.snar
if [ "$1" = "" ]; then
echo "Usage: backupscript-promptless.sh NAME DIRECTORY DESTINATION k/i"
exit 0
elif [ "$4" = "" ]; then
echo "Not enough arguments"
exit 0
#else
#echo "Given arguments: $1 $2 $3 $4"
fi
# Test ob Zielspeicherort vorhanden. Wenn nicht, erstellen
if [ ! -d "$3" ]; then
mkdir $3
fi
# Eigentliche Backuproutine
if [ "$4" = "k" ]; then
#Komplettes Backup
MYDATE=complete
#Alte Timestamps löschen
rm -f "$3/$TSNAME"
#Alte Backups löschen
rm -rf "$3/$LASTMONTHDIR.$1.d"
#Neue alte Backups in Ordner verschieben
mkdir "$3/$LASTMONTHDIR.$1.d"
mv -f "$3/$1".*.tgz "$3/$LASTMONTHDIR.$1.d"
elif [ "$4" = "i" ]; then
#Inkrementelles Backup
MYDATE=$(date +%y%m%d-%H%M)
else
echo "Unknown argument. Use k or i"
fi
#Abzug erstellen
tar czf "$3"/"$1".$MYDATE.tgz -g "$3/$TSNAME" $2 2> /dev/null