Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| USER=cgag | |
| HOME=/home/cgag | |
| source $HOME/.keychain/$USER-sh | |
| # TODO(cgag): write last backup to some sort of status file so I | |
| # can display last backup time in the i3 status bar. | |
| # TODO: host is somewhat of a misnomer | |
| # TODO: attic check is really slow, move it into | |
| # a separate script and run it less often? | |
| main() { | |
| # HOME_EXTERNAL="/mnt/home-external" | |
| # WORK_EXTERNAL="/mnt/work-external" | |
| # backup_important "cgag@accord:backups/coreos.borg" & | |
| # if mounted "$WORK_EXTERNAL"; then | |
| # backup_full "${WORK_EXTERNAL}/coreos.borg" & | |
| # else | |
| # echo "NOT MOUNTED: ${WORK_EXTERNAL}, SKIPPING" | |
| # fi | |
| # if mounted "$HOME_EXTERNAL"; then | |
| # backup_full "${HOME_EXTERNAL}/coreos.borg" & | |
| # else | |
| # echo "NOT MOUNTED: ${HOME_EXTERNAL}, SKIPPING" | |
| # fi | |
| if [ -d "/tank/backup" ]; then | |
| backup_full "/tank/backup/desktop.borg" & | |
| else | |
| echo "NOT MOUNTED: /tank/backup, SKIPPING" | |
| fi | |
| # should always work | |
| # here: backup rsync.net | |
| backup_full 1387@rsyncnet:backup & | |
| wait | |
| echo 'Done with backups.' | |
| } | |
| mounted() { | |
| local mount=$1 | |
| grep -qs "$mount" /proc/mounts | |
| } | |
| backup_full() { | |
| # TODO(cgag): maybe remove | |
| BORG_RSH='/home/cgag/bin/pv-wrapper.sh ssh' | |
| local repo=$1 | |
| echo "Running full home backup to $repo" | |
| pass=$(cat /home/cgag/.ssh/.atticpass) | |
| # TODO(cgag): exclude video dir? | |
| BORG_PASSPHRASE=$pass borg create \ | |
| --remote-path=borg1 \ | |
| -v \ | |
| --stats \ | |
| --exclude "*/.stack" \ | |
| --exclude "*/.stack-work" \ | |
| --exclude "*/.haskell-vim-now" \ | |
| --exclude "*/.cabal-sandbox" \ | |
| --exclude "*/.cargo" \ | |
| --exclude "*/.cache" \ | |
| --exclude-caches \ | |
| --one-file-system \ | |
| --compression lz4 \ | |
| "$repo"::'{hostname}-{now:%Y-%m-%dT%H:%M:%S}' \ | |
| ~ | |
| #check "$repo" | |
| prune "$repo" | |
| } | |
| # backup_important() { | |
| # local repo=$1 | |
| # echo "Running important backup to $repo" | |
| # pass=$(cat /home/cgag/.ssh/.atticpass) | |
| # # better to backup everything but not video, instead of this whole list? | |
| # # edit: oh that's what backup full does | |
| # BORG_PASSPHRASE=$pass borg create -v --stats "$repo"::'{hostname}-{now:%Y-%m-%d}' \ | |
| # --exclude "*/.stack" \ | |
| # --exclude "*/.haskell-vim-now" \ | |
| # --exclude "*/.stack-work/" \ | |
| # --exclude "*/.cabal-sandbox/" \ | |
| # --exclude "*/.cargo" \ | |
| # --exclude "*/target" \ | |
| # --exclude "src/others" \ | |
| # --exclude-caches \ | |
| # --one-file-system \ | |
| # ~/doc \ | |
| # ~/src \ | |
| # ~/play \ | |
| # ~/.ssh \ | |
| # ~/notes \ | |
| # ~/kp.kdbx \ | |
| # # check "$repo" | |
| # prune "$repo" | |
| # } | |
| check() { | |
| local repo=$1 | |
| echo "Checking $repo" | |
| pass=$(cat /home/cgag/.ssh/.atticpass) | |
| BORG_PASSPHRASE=$pass borg check -v "$repo" | |
| } | |
| prune() { | |
| # calling host repo would make more sense | |
| local repo=$1 | |
| echo "Pruning $repo" | |
| pass=$(cat /home/cgag/.ssh/.atticpass) | |
| BORG_PASSPHRASE=$pass borg prune \ | |
| -v \ | |
| --list \ | |
| --stats \ | |
| --prefix '{hostname}-' \ | |
| --keep-within=1d \ | |
| --keep-daily=7 \ | |
| --keep-weekly=4 \ | |
| --keep-monthly=-1 | |
| "$repo" | |
| } | |
| main |