38 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
#!/bin/ash
 | 
						|
: "${RESTIC_REPOSITORY:?Need the restic repository}"
 | 
						|
: "${AWS_ACCESS_KEY_ID:?Need the access key id}"
 | 
						|
: "${AWS_SECRET_ACCESS_KEY:?Need the secret access key}"
 | 
						|
: "${RESTIC_PASSWORD:?Need the restic password}"
 | 
						|
: "${LOG_PATH:-./restic-backup.log}"
 | 
						|
: "${seafile_data_local:-/seafile}"
 | 
						|
 | 
						|
# need to securely provide password: https://restic.readthedocs.io/en/latest/faq.html#how-can-i-specify-encryption-passwords-automatically
 | 
						|
restic snapshots > /dev/null || restic init
 | 
						|
 | 
						|
#Define a timestamp function
 | 
						|
timestamp() {
 | 
						|
date "+%b %d %Y %T %Z"
 | 
						|
}
 | 
						|
 | 
						|
# insert timestamp into log
 | 
						|
printf "\n\n"
 | 
						|
echo "-------------------------------------------------------------------------------" | tee -a $LOG_PATH
 | 
						|
echo "$(timestamp): restic-backup.sh started" | tee -a $LOG_PATH
 | 
						|
 | 
						|
# Run Backups
 | 
						|
restic backup $seafile_data_local | tee -a $LOG_PATH
 | 
						|
 | 
						|
# Remove snapshots according to policy
 | 
						|
# If run cron more frequently, might add --keep-hourly 24
 | 
						|
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 7  | tee -a $LOG_PATH
 | 
						|
 | 
						|
# Remove unneeded data from the repository
 | 
						|
restic prune | tee -a $LOG_PATH
 | 
						|
 | 
						|
# Check the repository for errors
 | 
						|
restic check | tee -a $LOG_PATH
 | 
						|
 | 
						|
# insert timestamp into log
 | 
						|
printf "\n\n"
 | 
						|
echo "-------------------------------------------------------------------------------" | tee -a $LOG_PATH
 | 
						|
echo "$(timestamp): restic-backup.sh finished" | tee -a $LOG_PATH |