Created
April 20, 2023 08:40
-
-
Save fbennett/dcb066fc71e116d3e35d2ec9e144ab71 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 | |
## NOTE: to merge divergent backups use: | |
## | |
## rsync -aiuP <older>src/ <newer>dest/ | |
## | |
set -e | |
BDIR=/path/to/plugged/usb/disk/BACKUPS | |
TARGETS="/paths /to /back /up" | |
OWNER_AND_GROUP="owner:owner" | |
if [ ! -d "${BDIR}" ]; then | |
echo "Insert backup USB" | |
exit 0 | |
fi | |
# Report out old and new backup times | |
if [ -f "${BDIR}/info/time.txt" ]; then | |
OLD_TIME=$(cat "${BDIR}/info/time.txt") | |
else | |
echo "Failed to find file ${BDIR}/info/time.txt file, aborting." | |
echo "Touch it to create an empty file there to proceed." | |
exit 0 | |
fi | |
NEW_TIME=$(LANG=en date +"%F:%H") | |
# Make the log file | |
# echo "" > "${BDIR}/info/rsync-$(cat ${BDIR}/info/time.txt).log" | |
# Make the target directory | |
if [ ! -d "${BDIR}/BACKUP-IN-PROGRESS" ]; then | |
sudo mkdir "${BDIR}/BACKUP-IN-PROGRESS" | |
sudo chown ${OWNER_AND_GROUP} "${BDIR}/BACKUP-IN-PROGRESS" | |
fi | |
cd ~/. | |
sudo rsync -avhPR \ | |
--stats \ | |
--log-file="${BDIR}/info/rsync-${NEW_TIME}.log" \ | |
--exclude-from="${BDIR}/info/exclude.txt" \ | |
--link-dest="${BDIR}/${OLD_TIME}" \ | |
${TARGETS} \ | |
"${BDIR}/BACKUP-IN-PROGRESS" | |
sudo echo "Last backup: ${OLD_TIME}" | |
echo "This backup: ${NEW_TIME}" | |
#move | |
sudo mv "${BDIR}/BACKUP-IN-PROGRESS" "${BDIR}/${NEW_TIME}" | |
#overwrite old time.txt file with new time | |
sudo echo ${NEW_TIME} > "${BDIR}/info/time.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment