add inpsiration to Readme
This commit is contained in:
parent
8ab14ce767
commit
f253018def
2 changed files with 113 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
# backup
|
||||
# Backup
|
||||
A flexible backup script for backing up linux system using rsync, ssh, cron and other common shell commands.
|
||||
|
||||
## Inspiration
|
||||
[Backup mit RSYNC](https://wiki.ubuntuusers.de/Skripte/Backup_mit_RSYNC/)
|
||||
[rsync linux backup script](https://ctaas.de/rsync.htm)
|
||||
[Easy Automated Snapshot-Style Backups with Linux and Rsync](http://www.mikerubel.org/computers/rsync_snapshots/)
|
||||
|
||||
A backup script for linux systems using rsync and ssh.
|
106
backup.sh
Executable file
106
backup.sh
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/bin/bash
|
||||
# Simple backup with rsync
|
||||
# local-mode, tossh-mode, fromssh-mode
|
||||
|
||||
SOURCES=(/root /etc /home /boot )
|
||||
TARGET="/home/sterzy/backup"
|
||||
|
||||
# edit or comment with "#"
|
||||
#LISTPACKAGES=listdebianpackages # local-mode and tossh-mode
|
||||
MONTHROTATE=monthrotate # use DD instead of YYMMDD
|
||||
|
||||
RSYNCCONF=(--delete)
|
||||
#MOUNTPOINT="/media/daten" # check local mountpoint
|
||||
MAILREC="hi@sterzy.com"
|
||||
|
||||
SSHUSER="sterzy"
|
||||
#FROMSSH="fromssh-server"
|
||||
TOSSH="backup-pi"
|
||||
SSHPORT=22
|
||||
|
||||
### do not edit ###
|
||||
|
||||
MOUNT="/bin/mount"; FGREP="/bin/fgrep"; SSH="/usr/bin/ssh"
|
||||
LN="/bin/ln"; ECHO="/bin/echo"; DATE="/bin/date"; RM="/bin/rm"
|
||||
DPKG="/usr/bin/dpkg"; AWK="/usr/bin/awk"; MAIL="/usr/bin/mail"
|
||||
CUT="/usr/bin/cut"; TR="/usr/bin/tr"; RSYNC="/usr/bin/rsync"
|
||||
LAST="last"; INC="--link-dest=$TARGET/$LAST"
|
||||
|
||||
LOG=$0.log
|
||||
$DATE > $LOG
|
||||
|
||||
if [ "${TARGET:${#TARGET}-1:1}" != "/" ]; then
|
||||
TARGET=$TARGET/
|
||||
fi
|
||||
|
||||
if [ "$LISTPACKAGES" ] && [ -z "$FROMSSH" ]; then
|
||||
$ECHO "$DPKG --get-selections | $AWK '!/deinstall|purge|hold/'|$CUT -f1 | $TR '\n' ' '" >> $LOG
|
||||
$DPKG --get-selections | $AWK '!/deinstall|purge|hold/'|$CUT -f1 |$TR '\n' ' ' >> $LOG 2>&1
|
||||
fi
|
||||
|
||||
if [ "$MOUNTPOINT" ]; then
|
||||
MOUNTED=$($MOUNT | $FGREP "$MOUNTPOINT");
|
||||
fi
|
||||
|
||||
if [ -z "$MOUNTPOINT" ] || [ "$MOUNTED" ]; then
|
||||
if [ -z "$MONTHROTATE" ]; then
|
||||
TODAY=$($DATE +%y%m%d)
|
||||
else
|
||||
TODAY=$($DATE +%d)
|
||||
fi
|
||||
|
||||
if [ "$SSHUSER" ] && [ "$SSHPORT" ]; then
|
||||
S="$SSH -p $SSHPORT -l $SSHUSER";
|
||||
fi
|
||||
|
||||
for SOURCE in "${SOURCES[@]}"
|
||||
do
|
||||
if [ "$S" ] && [ "$FROMSSH" ] && [ -z "$TOSSH" ]; then
|
||||
$ECHO "$RSYNC -e \"$S\" -avR \"$FROMSSH:$SOURCE\" ${RSYNCCONF[@]} $TARGET$TODAY $INC" >> $LOG
|
||||
$RSYNC -e "$S" -avR "$FROMSSH:\"$SOURCE\"" "${RSYNCCONF[@]}" "$TARGET"$TODAY $INC >> $LOG 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
ERROR=1
|
||||
fi
|
||||
fi
|
||||
if [ "$S" ] && [ "$TOSSH" ] && [ -z "$FROMSSH" ]; then
|
||||
$ECHO "$RSYNC -e \"$S\" -avR \"$SOURCE\" ${RSYNCCONF[@]} \"$TOSSH:$TARGET$TODAY\" $INC " >> $LOG
|
||||
$RSYNC -e "$S" -avR "$SOURCE" "${RSYNCCONF[@]}" "$TOSSH:\"$TARGET\"$TODAY" $INC >> $LOG 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
ERROR=1
|
||||
fi
|
||||
fi
|
||||
if [ -z "$S" ]; then
|
||||
$ECHO "$RSYNC -avR \"$SOURCE\" ${RSYNCCONF[@]} $TARGET$TODAY $INC" >> $LOG
|
||||
$RSYNC -avR "$SOURCE" "${RSYNCCONF[@]}" "$TARGET"$TODAY $INC >> $LOG 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
ERROR=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$S" ] && [ "$TOSSH" ] && [ -z "$FROMSSH" ]; then
|
||||
$ECHO "$SSH -p $SSHPORT -l $SSHUSER $TOSSH $LN -nsf $TARGET$TODAY $TARGET$LAST" >> $LOG
|
||||
$SSH -p $SSHPORT -l $SSHUSER $TOSSH "$LN -nsf \"$TARGET\"$TODAY \"$TARGET\"$LAST" >> $LOG 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
ERROR=1
|
||||
fi
|
||||
fi
|
||||
if ( [ "$S" ] && [ "$FROMSSH" ] && [ -z "$TOSSH" ] ) || ( [ -z "$S" ] ); then
|
||||
$ECHO "$LN -nsf $TARGET$TODAY $TARGET$LAST" >> $LOG
|
||||
$LN -nsf "$TARGET"$TODAY "$TARGET"$LAST >> $LOG 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
ERROR=1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
$ECHO "$MOUNTPOINT not mounted" >> $LOG
|
||||
ERROR=1
|
||||
fi
|
||||
$DATE >> $LOG
|
||||
if [ -n "$MAILREC" ]; then
|
||||
if [ $ERROR ];then
|
||||
$MAIL -s "Error Backup $LOG" $MAILREC < $LOG
|
||||
else
|
||||
$MAIL -s "Backup $LOG" $MAILREC < $LOG
|
||||
fi
|
||||
fi
|
Loading…
Reference in a new issue