Having decided on using restic moving forwards, I've written several scripts, so here is the main one, 'resticup'.

Resticup

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash

#: Title            : resticup
#: Date             : 17 August 2017
#: Author           : Sharon Kimble
#: Version          : 1.0
#: Description      : script to help in running restic for backups
#: License          : GNU GPL 3.0 or later

# Copyright (C) 2017 Sharon Kimble <[email protected]>

# Author: Sharon Kimble <[email protected]>

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

####################################################
# How to use.
# Change the lines in the '#Variables' section to fit your situation and 
# your file tree. And save it in ~/bin/resticup, and then run 'chmod +x ~/bin/resticup' to make it executable.
# Then put an entry for it in your crontab, this is mine -
# 00 */4 * * * DISPLAY=:0 /home/boudiccas/bin/resticup  #backup /home and let it run every 4 hours for backups.
#######################
# Variables
RESTIC_REPOSITORY=/mnt/backc/restic-back
logfile="/home/boudiccas/logs/backup-restic.txt"
BACKUP_DIRS="/home/boudiccas /var/www"
EXCLUDED_DIRS="/home/*/.cache ~/.gvfs"
###########

# Log all stdout+stderr 
exec > >(tee -a $logfile) 2>&1

/usr/bin/notify-send "Starting main backup..."


/usr/local/bin/restic -r $RESTIC_REPOSITORY -p ~/bin/restinpeace.txt backup $BACKUP_DIRS \
           --exclude $EXCLUDED_DIRS 


/usr/local/bin/restic -r $RESTIC_REPOSITORY -p ~/bin/restinpeace.txt forget --keep-hourly 5 \ 
      --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 10


/usr/local/bin/restic -r $RESTIC_REPOSITORY -p ~/bin/restinpeace.txt snapshots

if [ "$?" -ne 0 ]; then
  notify-send "Unable to finish main backup"
  exit 1
else

  notify-send "Finished main backup"

  du -sh /mnt/backc/restic-back

echo 'Sending Backup report : Backup of restic completed', $(date -R) 'logged to' $logfile
echo '####################################'

fi

When run as shown in the 'How to use' section and running from a cronjob it will produce an output like this -

using parent snapshot 8eea71af
scan [/home/boudiccas]
[5:31] 200751 directories, 1464687 files, 210.120 GiB
scanned 200751 directories, 1464687 files in 5:31
warning for /home/boudiccas/.config/freeter/Partitions/freeter/Cache/data_0: file has changed
[25:42] 100.00%  0B/s  210.120 GiB / 210.120 GiB  1665442 / 1665438 items  0 errors  ETA 0:00 

duration: 25:42, 139.47MiB/s
snapshot cf05f1e0 saved
snapshots for host London, paths: [/home/boudiccas]:

keep 6 snapshots:
ID        Date                 Host        Tags        Directory
----------------------------------------------------------------------
cf05f1e0  2017-08-19 08:06:05  London                  /home/boudiccas
8eea71af  2017-08-19 06:06:41  London                  /home/boudiccas
921aaf77  2017-08-18 20:06:28  London                  /home/boudiccas
ecef0016  2017-08-18 18:06:47  London                  /home/boudiccas
758f5d0c  2017-08-17 23:04:18  London                  /home/boudiccas
3f35d303  2017-08-16 20:19:59  London                  /home/boudiccas

remove 1 snapshots:
ID        Date                 Host        Tags        Directory
----------------------------------------------------------------------
ea848396  2017-08-18 16:06:28  London                  /home/boudiccas

ID        Date                 Host        Tags        Directory
----------------------------------------------------------------------
3f35d303  2017-08-16 20:19:59  London                  /home/boudiccas
758f5d0c  2017-08-17 23:04:18  London                  /home/boudiccas
ecef0016  2017-08-18 18:06:47  London                  /home/boudiccas
921aaf77  2017-08-18 20:06:28  London                  /home/boudiccas
8eea71af  2017-08-19 06:06:41  London                  /home/boudiccas
cf05f1e0  2017-08-19 08:06:05  London                  /home/boudiccas
155G    /mnt/backc/restic-back
Sending Backup report : Backup of restic completed, Sat, 19 Aug 2017 08:31:50 +0100 logged to /home/boudiccas/logs/backup-restic.txt
####################################

This output goes to your email account, and also to the log file that you set under 'logfile' under Variables.



Comments

comments powered by Disqus