Last active
September 12, 2021 18:21
-
-
Save aivanise/696a262f358050d02361f2d191b9a919 to your computer and use it in GitHub Desktop.
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/bash | |
# backup full image of the SD card to arbitrary directory and keep a number of them | |
# requires basyn: https://github.com/stvorl/basyn | |
# if parameter given, override the destination (i.e. an alternative sdcard) | |
DEST=/mnt/eksterni/backup/rock64-microsd.img | |
DESTDIR=/mnt/eksterni/backup/ | |
DESTKEEPDAYS=30 | |
if [[ -z "$1" ]]; then | |
if [[ ! -d $DESTDIR ]]; then | |
echo $DESTDIR does not exist, skipping backup | |
exit | |
fi | |
if [[ -f /tmp/nobackup ]]; then | |
echo /tmp/nobackup exists, skipping backup | |
exit | |
fi | |
if [[ $(date +%u) -eq 1 ]]; then | |
mv ${DEST}.old.3.bz2 ${DEST}.old.$(date +%Y-%U).bz2 | |
find $DESTDIR -mtime +$DESTKEEPDAYS | xargs --no-run-if-empty rm | |
else | |
rm -f ${DEST}.old.3.bz2 | |
fi | |
mv ${DEST}.old.2.bz2 ${DEST}.old.3.bz2 | |
mv ${DEST}.old.1.bz2 ${DEST}.old.2.bz2 | |
mv ${DEST}.old.bz2 ${DEST}.old.1.bz2 | |
pbzip2 -k -f ${DEST}.old | |
rsync -a --inplace $DEST ${DEST}.old | |
else | |
set -x | |
DEST="$1" | |
fi | |
if [[ "$(stat -c %s $DEST)" -ne 15931539456 ]]; then | |
echo $DEST: wrong destination size, bailing out | |
exit | |
fi | |
systemctl isolate rescue-ssh | |
sleep 10 | |
systemctl stop systemd-journald.socket | |
systemctl stop systemd-journald-audit.socket | |
systemctl stop systemd-journald-dev-log.socket | |
systemctl stop systemd-journald | |
systemctl stop systemd-udevd-control.socket | |
systemctl stop systemd-udevd-kernel.socket | |
systemctl stop systemd-udevd | |
#fuser -v -m / 2>&1 | fgrep F | |
[[ -t 0 ]] && VERBOSE="--progress --verbose" | |
/root/bin/basyn -l /dev/mmcblk1 -r $DEST -a push -m sync --buffer=4096 --chunk=1 --stat $VERBOSE | |
systemctl isolate default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment