I'm fairly new to Linux and I running Ubuntu 20.04 on a raspberry pi 4. I wanted to keep regular snapshots of the system so I've installed Timeshift. However, I noticed that the disk space was quite large. I'd like to keep some extra snapshots backup away from the system so I've also been backing up the snapshots to by Google Drive account using Tar to create a backup of the snapshot and Rclone to get it to Drive. I've got this working successfully.
However, should the worst happen, can actually use these tarred files if I can get them back to the timeshift snapshot directories? Here's the script I run in cron (Timeshift is running in its own, perhaps that's not right though).
Code:
#!/bin/bash
readonly SCRIPT_NAME=$(basename $0)
log() {
echo "$@"
logger -p user.notice -t $SCRIPT_NAME "$@"
}
err() {
echo "$@" >&2
logger -p user.error -t $SCRIPT_NAME "$@"
}
#First lets see what snapshots are available and create tar.gz files for them if they are not already there
cd /timeshift/snapshots/
log "Changed directory to " $(pwd)
for i in *
do
#is i a directory? If not continue
if [ ! -d ${i} ]
then
continue
fi
log "check if ./snapback/${i%/}.tar.gz exists and if not create it"
if [[ ! -f "../snapback/${i%/}.tar.gz" ]]
then
tar -czvf "../snapback/${i%/}.tar.gz" "$i"
log "created: ../snapback/${i%/}.tar.gz"
fi
done
#Next see what .tar.gz files are present and delete them if their snapshots are deleted
cd /timeshift/snapback/
log "Changed directory to " $(pwd)
for i in *
do
#is i a file? If not continue
if [ ! -f ${i} ]
then
continue
fi
log "check if ./snapshots/${i%.tar.gz} exists and if not delete the file"
if [ ! -d "../snapshots/${i%.tar.gz}" ]
then
rm $i
log "Deleted $i"
fi
done
#Finally Backup any .tar.gz to Google Drive files that are not backed up and delete those that are no longer there
log "Begin Sync with Google Drive"
/usr/bin/rclone sync --update --verbose --transfers 30 --checkers 8 --contimeout 60s --timeout 300s --retries 3 --low-level-retries 10 --stats 10s --drive-use-trash --include "*.tar.gz" "/timeshift/snapback" "GoogleDrive-SystemBackup:Pi/Backup"
log "Completed Sync with Google Drive"
Bookmarks