Skip to content

Instantly share code, notes, and snippets.

@MatthewVance
Created May 18, 2019 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MatthewVance/d0171b192dc50d6e9c5f1bda3b666ca8 to your computer and use it in GitHub Desktop.
Save MatthewVance/d0171b192dc50d6e9c5f1bda3b666ca8 to your computer and use it in GitHub Desktop.
Example script and systemd scheduled service to sync local repo to AWS S3. This is if you prefer to backup locally on your network and sync a copy to S3 rather than use Restic to automatically interface with a S3 based repo.
[Unit]
Description=Runs daily aws sync script
[Service]
Type=oneshot
ExecStart=/etc/restic/aws.sh
[Unit]
Description=Run aws-daily.service
[Timer]
Unit=restic-aws-daily.service
OnCalendar=*-*-* 02:30:00
[Install]
WantedBy=timers.target
#!/bin/bash
#: Title : Cloud Sync
#: Date : May 16, 2019
#: Author : Matt Vance
#: Version : 1.0
#: Description : This syncs Restic backup to AWS
#: License : MIT License (MIT)
# Copyright (C) 2019 Matthew Vance
#export AWS_CONFIG_FILE=/home/matt/.aws/config
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=us-east-2
export AWS_DEFAULT_OUTPUT=json
LOG=/var/log/restic/aws.log
#Define a timestamp function
timestamp() {
date "+%b %d %Y %T %Z"
}
# Add timestamp
echo "$(timestamp): restic aws sync started" | tee -a $LOG
echo "-------------------------------------------------------------------------------" | tee -a $LOG
/usr/local/bin/aws s3 sync \
'/Volumes/storage/matt/backup/repos' \
's3://restic.your-domain.com/repos/' \
--storage STANDARD \
--exclude "*.DS_Store" \
--delete \
--sse AES256 | tee -a $LOG
# Add timestamp
echo "-------------------------------------------------------------------------------" | tee -a $LOG
echo "$(timestamp): restic aws sync finished" | tee -a $LOG
printf "\n" | tee -a $LOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment