Compare commits
3 commits
e972c90fe5
...
a406cfe849
Author | SHA1 | Date | |
---|---|---|---|
a406cfe849 | |||
c734a085e7 | |||
718431b361 |
4 changed files with 47 additions and 20 deletions
45
backup.sh
45
backup.sh
|
@ -61,7 +61,7 @@ print_help () {
|
||||||
}
|
}
|
||||||
|
|
||||||
print_and_log () {
|
print_and_log () {
|
||||||
/usr/bin/ts "%Y-%m-%dT%H:%M:%S" | /usr/bin/tee -a $BACKUP_LOG
|
/usr/bin/env ts "%Y-%m-%dT%H:%M:%S" | /usr/bin/tee -a $BACKUP_LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
set -o errexit
|
set -o errexit
|
||||||
|
@ -70,6 +70,7 @@ set -o pipefail
|
||||||
ACTION=$1
|
ACTION=$1
|
||||||
DESTINATION=$2
|
DESTINATION=$2
|
||||||
INPUT="${@:3}"
|
INPUT="${@:3}"
|
||||||
|
RESTIC=$(which restic)
|
||||||
|
|
||||||
if [[ -z $DESTINATION && $ACTION == "help" ]]; then
|
if [[ -z $DESTINATION && $ACTION == "help" ]]; then
|
||||||
print_logo
|
print_logo
|
||||||
|
@ -105,7 +106,7 @@ else
|
||||||
"backup")
|
"backup")
|
||||||
if [[ $AC_POWER == 1 ]]; then
|
if [[ $AC_POWER == 1 ]]; then
|
||||||
echo "backing up to $DESTINATION." | print_and_log
|
echo "backing up to $DESTINATION." | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--cleanup-cache \
|
--cleanup-cache \
|
||||||
|
@ -120,7 +121,7 @@ else
|
||||||
;;
|
;;
|
||||||
"check")
|
"check")
|
||||||
echo "Checking backup repository at $DESTINATION" | print_and_log
|
echo "Checking backup repository at $DESTINATION" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -128,7 +129,7 @@ else
|
||||||
;;
|
;;
|
||||||
"find")
|
"find")
|
||||||
echo "Searching for $INPUT at $DESTINATION"
|
echo "Searching for $INPUT at $DESTINATION"
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -140,7 +141,7 @@ else
|
||||||
;;
|
;;
|
||||||
"init")
|
"init")
|
||||||
echo "Initializing backup repository at $DESTINATION" | print_and_log
|
echo "Initializing backup repository at $DESTINATION" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -148,7 +149,7 @@ else
|
||||||
;;
|
;;
|
||||||
"mount")
|
"mount")
|
||||||
echo "Mounting backup repository $DESTINATION at $INPUT" | print_and_log
|
echo "Mounting backup repository $DESTINATION at $INPUT" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -156,7 +157,7 @@ else
|
||||||
;;
|
;;
|
||||||
"restore")
|
"restore")
|
||||||
echo "Restoring from $DESTINATION, $INPUT" | print_and_log
|
echo "Restoring from $DESTINATION, $INPUT" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -164,7 +165,7 @@ else
|
||||||
;;
|
;;
|
||||||
"snapshots")
|
"snapshots")
|
||||||
echo "Listing snapshots on $DESTINATION"
|
echo "Listing snapshots on $DESTINATION"
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -172,7 +173,7 @@ else
|
||||||
;;
|
;;
|
||||||
"stats")
|
"stats")
|
||||||
echo "Printing statistics for $DESTINATION"
|
echo "Printing statistics for $DESTINATION"
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -180,23 +181,27 @@ else
|
||||||
;;
|
;;
|
||||||
"prune")
|
"prune")
|
||||||
if [[ $AC_POWER == 1 ]]; then
|
if [[ $AC_POWER == 1 ]]; then
|
||||||
|
hourly=6
|
||||||
|
daily=7
|
||||||
|
monthly=12
|
||||||
|
yearly=5
|
||||||
echo """
|
echo """
|
||||||
Pruning backups at $DESTINATION ...
|
Pruning backups at $DESTINATION ...
|
||||||
Keeping:
|
Keeping:
|
||||||
- 24 hourly backups
|
- $hourly hourly backups
|
||||||
- 90 daily backups
|
- $daily daily backups
|
||||||
- 12 monthly backups
|
- $monthly monthly backups
|
||||||
- 5 yearly backups
|
- $yearly yearly backups
|
||||||
""" | print_and_log
|
""" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
--prune \
|
--prune \
|
||||||
--keep-hourly=24 \
|
--keep-hourly=$hourly \
|
||||||
--keep-daily=90 \
|
--keep-daily=$daily \
|
||||||
--keep-monthly=12 \
|
--keep-monthly=$monthly \
|
||||||
--keep-yearly=5 \
|
--keep-yearly=$yearly \
|
||||||
forget | print_and_log
|
forget | print_and_log
|
||||||
else
|
else
|
||||||
echo "Not plugged in, canceling prune."
|
echo "Not plugged in, canceling prune."
|
||||||
|
@ -204,7 +209,7 @@ else
|
||||||
;;
|
;;
|
||||||
"unlock")
|
"unlock")
|
||||||
echo "Unlocking backup repository at $DESTINATION" | print_and_log
|
echo "Unlocking backup repository at $DESTINATION" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
@ -212,7 +217,7 @@ else
|
||||||
;;
|
;;
|
||||||
"clean")
|
"clean")
|
||||||
echo "Cleaning repository at $DESTINATION" | print_and_log
|
echo "Cleaning repository at $DESTINATION" | print_and_log
|
||||||
/usr/bin/restic \
|
RESTIC \
|
||||||
-r "$BACKUP_REPOSITORY" \
|
-r "$BACKUP_REPOSITORY" \
|
||||||
-p "$BACKUP_PASSWORD" \
|
-p "$BACKUP_PASSWORD" \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
|
22
launchd/net.andrew.backup.sh.plist
Normal file
22
launchd/net.andrew.backup.sh.plist
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>Label</key>
|
||||||
|
<string>net.andrew.backup.sh</string>
|
||||||
|
<key>ProgramArguments</key>
|
||||||
|
<array>
|
||||||
|
<string>touch</string>
|
||||||
|
<string>/tmp/helloworld</string>
|
||||||
|
</array>
|
||||||
|
<key>StartCalendarInterval</key>
|
||||||
|
<dict>
|
||||||
|
<key>Minute</key>
|
||||||
|
<integer>0</integer>
|
||||||
|
</dict>
|
||||||
|
<key>StandardOutPath</key>
|
||||||
|
<string>/var/log/testDaemon.log</string>
|
||||||
|
<key>StandardErrorPath</key>
|
||||||
|
<string>/var/log/testDaemon.log</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
Loading…
Reference in a new issue