Migration to Linux: Backup
Jump to navigation
Jump to search
You are here: /Migrating from macOS to Linux/Migration to Linux: Backup
Toolauswahl
- Bordmittel Pikabackup: Eher sehr spartanisch
- rsync: Klingt nach Mittel der Wahl
- Könnte man Versionierung mit rsync machen? Snapshots wie bei TimeMachine?
- Ja:
- https://github.com/rsnapshot/rsnapshot <- Overengineered? Why Perl?
- https://www.howtoforge.com/rsync_incremental_snapshot_backups <- KISS!!
- http://www.mikerubel.org/computers/rsync_snapshots/ <- KISS!!
- Ja:
- Könnte man Versionierung mit rsync machen? Snapshots wie bei TimeMachine?
- https://github.com/rdiff-backup/rdiff-backup#1-installation <- Overengineered? Why Python?
- https://software.opensuse.org/package/rdiff-backup
- https://www.maketecheasier.com/time-machine-alternatives-linux/
- https://alternativeto.net/software/time-machine/?platform=linux
Tests
- Déjà Dup
- Cronopete
- Back in Time
- Timeshift
- Restic
- Pika Backup
- Rsync and cp: This works actually pretty good!
Solution
#!/bin/bash
#set -x
#
# Author: Heiko
# Source: TBD
# Purpose: Create Timemachine-Like Backups (like snapshots)
# Globals
GFOLDERSOURCEROOT01="/home/heiko"
GFOLDERSOURCEROOT02="/etc"
GFOLDERSOURCEROOT03="/var/lib/libvirt"
GFOLDERSOURCEROOT04="/usr"
GFOLDERSOURCEROOT05="/run/media/heiko/f595f49a-f483-4e65-9559-aef130f2a1a6"
GFILEEXCLUDES="/home/heiko/bin/etc/backup_exclude.cfg"
GTARGETFILESYSTEMID="c9be69cb-32b9-4ef8-8f02-5d3926bc49c2"
GFOLDERTARGETMOUNTPOINT="`mount | grep run/media/heiko | grep "${GTARGETFILESYSTEMID}" | awk '{printf $3}'`"
if [ -z "${GFOLDERTARGETMOUNTPOINT}" ]; then
echo "Target \"${GTARGETFILESYSTEMID}\" not found."
exit 1
fi
GFOLDERTARGETROOT="${GFOLDERTARGETMOUNTPOINT}/_Backups"
GFOLDERTARGETCURRENT=${GFOLDERTARGETROOT}/current
echo "Backup source root 01: ${GFOLDERSOURCEROOT01}"
echo "Backup source root 02: ${GFOLDERSOURCEROOT02}"
echo "Backup source root 03: ${GFOLDERSOURCEROOT03}"
echo "Backup source root 04: ${GFOLDERSOURCEROOT04}"
echo "Backup source root 05: ${GFOLDERSOURCEROOT05}"
echo "Backup target root : ${GFOLDERTARGETROOT}"
GMAXAGEDAYS=60 # The number of days after which old backups will be deleted
date
# Check user
if [ "`whoami`" != "root" ]; then
echo "Not running as root."
echo "Bailing out. Bye."
exit 1
fi
# Check target
if [ ! -d "${GFOLDERTARGETROOT}" ]; then
echo "Target \"${GFOLDERTARGETROOT}\" seems to be invalid."
echo "Bailing out. Bye."
exit 1
fi
# If missing, create current folder
test ! -d "${GFOLDERTARGETCURRENT}" && mkdir "${GFOLDERTARGETCURRENT}"
# Create new target folder (w/ date)
GDATENOW="`date '+%Y-%m-%d_%H-%M-%S'`"
GFOLDERTARGETNOW="${GFOLDERTARGETROOT}/${GDATENOW}"
mkdir "${GFOLDERTARGETNOW}"
echo "Backup target for this run: ${GFOLDERTARGETNOW}"
echo "Continuing in 5 seconds...(CTRL-C to cancel)"
sleep 5
date
# RUN RSYNC INTO CURRENT
echo "Syncing to ${GFOLDERTARGETCURRENT}..."
if [ 23 -eq 23 ]; then
rsync -aR --delete --delete-excluded --exclude-from="${GFILEEXCLUDES}" "${GFOLDERSOURCEROOT01}" "${GFOLDERSOURCEROOT02}" "${GFOLDERSOURCEROOT03}" "${GFOLDERSOURCEROOT04}" "${GFOLDERSOURCEROOT05}" "${GFOLDERTARGETCURRENT}"
fi
# Output date to see how long it took
if [ "$?" -ne 0 -a 23 -eq 42 ]; then
echo "Sync failed. Bailing out. Try again!" # TODO: Might try some times until bailing out?
exit "$?"
fi
echo "Syncing to ${GFOLDERTARGETCURRENT}...DONE"
# UPDATE THE MTIME TO REFLECT THE SNAPSHOT TIME
touch "${GFOLDERTARGETCURRENT}"
# MAKE HARDLINK COPY
date
echo "Copying to ${GFOLDERTARGETNOW}..."
cp -al "${GFOLDERTARGETCURRENT}"/* "${GFOLDERTARGETNOW}/"
echo "Copying to ${GFOLDERTARGETNOW}...DONE"
# REMOVE OLD BACKUPS #TODO also make this disk space related, keep as much as you can. delet only when necessary!
for FILE in "$( find "${GFOLDERTARGETROOT}" -maxdepth 1 -type d -mtime +${GMAXAGEDAYS} | grep -v current)"
do
# $RM -Rf $FILE
echo "NOT REMOVING $FILE - FIX ME!"
done
# Output date to see how long it took
date
# EOF