Skip to content

Instantly share code, notes, and snippets.

@samber
Last active June 22, 2020 21:33
Show Gist options
  • Save samber/6efff2828ff6d7bd929ea33598569c17 to your computer and use it in GitHub Desktop.
Save samber/6efff2828ff6d7bd929ea33598569c17 to your computer and use it in GitHub Desktop.
Time-machine with restic

Time-machine with restic

Features

  • Differential backups
  • Deduplication
  • Encrypted ❤️
  • Backup cleaning
  • Less than 1€ a month

150k files scanned in < 30s, almost no CPU involved.

Setup

1- Sign-up to backblaze.com for a 10Go B2 free-tier

2- Create a bucket + API key with limited permissions

# init repository

RESTIC_PASSWORD=*** B2_ACCOUNT_ID=*** B2_ACCOUNT_KEY=*** /usr/local/bin/restic -r b2:time-machine:project init
# add the cron tasks
crontab -e
# if cron tasks are not executed as root, then:

touch /var/log/restic.log.1 /var/log/restic.log.2
chown samber:staff /var/log/restic.log.1 /var/log/restic.log.2
# backuping /Users/samber/project => every 30 minutes
*/30 * * * * RESTIC_PASSWORD=*** B2_ACCOUNT_ID=*** B2_ACCOUNT_KEY=*** time /usr/bin/nice -n 10 /usr/local/bin/restic -r b2:time-machine:project backup --verbose --exclude='*/node_modules' --exclude='*.o' --exclude='*.pyc' --exclude='*/vendors/' --exclude='*/vendor/' --exclude='*/scala-2*/' /Users/samber/project >> /var/log/restic.log.1 2>> /var/log/restic.log.2
# pruning backups older than 10 days => every evening
42 23 * * * RESTIC_PASSWORD=*** B2_ACCOUNT_ID=*** B2_ACCOUNT_KEY=*** time /usr/local/bin/restic -r b2:time-machine:project forget --keep-within 10d >> /var/log/restic.log.1 2>> /var/log/restic.log.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment