#!/bin/bash # # backup-rm2 # John Simpson 2023-06-29 # # Back up the reMarkable 2 tablet, using rsync with the '--link-dest' option # so each backup only "contains" the files which changed from the previous # backup. # # Requirements: # # - SSH access to the tablet. Ideally you should have key-based authentication # set up, otherwise you'll have to type the tablet's password when running # the script. # # - The location where you're storing the backups should be on a UNIX-type # filesystem which supports "hard links" (i.e. multiple filenames pointing # to the same inode). This is true of most Linux filesytems, as well as the # macOS "HFS", "HFS+", and "APFS" filesystems. # # - rsync version 3.1.1 or higher. In earlier versions (such as the version # that Apple includes with macOS), the '--link-dest' option didn't use hard # links, and every backup conained a full copy of the tablet's filesystem, # which took longer and used a LOT more disk space. # # If you're using macOS and are stuck with its ancient version of rsync, you # can install a newer/working version from Homebrew. https://brew.sh/ ######################################## # How to access the tablet. # - The last character should be "/". TABLET="root@10.11.99.1:/" ######################################## # Where you plan to store the backup images. BACKUPS="$HOME/rm2-backups/" ############################################################################### ############################################################################### ############################################################################### # # Make sure the location where we're storing the backups, exists. if [[ ! -d "$BACKUPS" ]] then echo "ERROR: '$BACKUPS' does not exist or is not a directory, cannot continue" exit 1 fi ######################################## # Get current timestamp, used for the backup directory name. NOW="$( date -u '+%Y-%m-%dT%H%M%SZ' )" ######################################## # Find the most recent previous backup. # - This assumes that the timestamps all start with "2", and that the 'ls' # command sorts the names correctly. THIS WILL BREAK in the year 3000. PREV="$( ls -d1 "$BACKUPS"/2* | tail -1 )" if [[ -n "$PREV" ]] then LINKPREV="--link-dest=$PREV" else LINKPREV="" fi ############################################################################### # # Back up the files set -x rsync -avzHl $LINKPREV \ --exclude /dev \ --exclude /proc \ --exclude /run \ --exclude /sys \ "$TABLET" \ "${BACKUPS%/}/$NOW/"