Sfoglia il codice sorgente

init

tags/v1.0.0^0
Robin Thoni 6 anni fa
commit
7ea2b1dbae

+ 4
- 0
.gitignore Vedi File

@@ -0,0 +1,4 @@
1
+*.swp
2
+data
3
+docker-compose.override.yml
4
+env_override

+ 21
- 0
docker-compose.yml Vedi File

@@ -0,0 +1,21 @@
1
+version: '2'
2
+
3
+services:
4
+    rsnapshot:
5
+        build: ./rsnapshot
6
+        container_name: rsnapshot-rsnapshot
7
+#        restart: unless-stopped
8
+        networks:
9
+            rsnapshot.internal.docker:
10
+                aliases:
11
+                    - rsnapshot.rsnapshot.internal.docker
12
+        volumes:
13
+            - ./data/rsnapshot/backup:/data/backup/
14
+            - ./data/rsnapshot/config:/etc/rsnapshot/
15
+            - ./data/ssh/:/root/.ssh/
16
+            - ./data/rclone/:/root/.config/rclone/
17
+        env_file:
18
+            - env
19
+
20
+networks:
21
+    rsnapshot.internal.docker:

+ 3
- 0
env Vedi File

@@ -0,0 +1,3 @@
1
+SSMTP_ROOT=root@example.com
2
+SSMTP_MAILHUB=172.17.0.1:10025
3
+SSMTP_MAILDOMAIN=example.com

+ 25
- 0
rsnapshot/Dockerfile Vedi File

@@ -0,0 +1,25 @@
1
+FROM robinthoni/debian-multiarch:jessie
2
+
3
+ARG CONFIG_DIR=/etc/default/config-files/
4
+
5
+RUN apt-get update &&\
6
+    apt-get install -y wget ssmtp rsnapshot cron &&\
7
+    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
8
+    rm /etc/cron.*/*
9
+
10
+RUN wget -O /tmp/rclone.deb 'https://downloads.rclone.org/v1.41/rclone-v1.41-linux-amd64.deb' && \
11
+    dpkg -i /tmp/rclone.deb && rm /tmp/rclone.deb
12
+
13
+COPY ./vars-vars /etc/vars-vars
14
+
15
+COPY ./vars-files /etc/vars-files
16
+
17
+COPY ./common.sh /common.sh
18
+
19
+COPY run.sh /run.sh
20
+
21
+RUN mkdir "${CONFIG_DIR}"
22
+
23
+COPY ./config "${CONFIG_DIR}"
24
+
25
+CMD ["/run.sh"]

+ 41
- 0
rsnapshot/common.sh Vedi File

@@ -0,0 +1,41 @@
1
+export CONFIG_DIR="/etc/default/config-files/"
2
+
3
+resolv_host()
4
+{
5
+  hostname="${1}"
6
+  ip=$(getent hosts "${hostname}" | cut -d' ' -f1)
7
+  echo "${ip}"
8
+}
9
+
10
+replace_var()
11
+{
12
+  file="${1}"
13
+  var="${2}"
14
+  sed -e "s?${var}?${!var}?g" -i "${file}"
15
+}
16
+
17
+replace_vars()
18
+{
19
+  file="${1}"
20
+  for var in $(cat /etc/vars-vars)
21
+  do
22
+    replace_var "${file}" "${var}"
23
+  done
24
+}
25
+
26
+replace_files()
27
+{
28
+  cat /etc/vars-files | while read line
29
+  do
30
+    filesrc="${CONFIG_DIR}$(echo "${line}" | awk '{print $1}')"
31
+    filedst=$(echo "${line}" | awk '{print $2}')
32
+    if [ -f "${filesrc}" ]
33
+    then
34
+      echo "Expanding file ${filesrc} to ${filedst}"
35
+      cp "${filesrc}" "${filedst}"
36
+      replace_vars "${filedst}"
37
+    else
38
+      echo "File ${filesrc} does not exist. Skipping."
39
+    fi
40
+  done
41
+}

+ 260
- 0
rsnapshot/config/rsnapshot.conf Vedi File

@@ -0,0 +1,260 @@
1
+#################################################
2
+# rsnapshot.conf - rsnapshot configuration file #
3
+#################################################
4
+#                                               #
5
+# PLEASE BE AWARE OF THE FOLLOWING RULES:       #
6
+#                                               #
7
+# This file requires tabs between elements      #
8
+#                                               #
9
+# Directories require a trailing slash:         #
10
+#   right: /home/                               #
11
+#   wrong: /home                                #
12
+#                                               #
13
+#################################################
14
+
15
+#######################
16
+# CONFIG FILE VERSION #
17
+#######################
18
+
19
+config_version	1.2
20
+
21
+###########################
22
+# SNAPSHOT ROOT DIRECTORY #
23
+###########################
24
+
25
+# All snapshots will be stored under this root directory.
26
+#
27
+snapshot_root	/data/backup/
28
+
29
+# If no_create_root is enabled, rsnapshot will not automatically create the
30
+# snapshot_root directory. This is particularly useful if you are backing
31
+# up to removable media, such as a FireWire or USB drive.
32
+#
33
+#no_create_root	1
34
+
35
+#################################
36
+# EXTERNAL PROGRAM DEPENDENCIES #
37
+#################################
38
+
39
+# LINUX USERS:   Be sure to uncomment "cmd_cp". This gives you extra features.
40
+# EVERYONE ELSE: Leave "cmd_cp" commented out for compatibility.
41
+#
42
+# See the README file or the man page for more details.
43
+#
44
+cmd_cp		/bin/cp
45
+
46
+# uncomment this to use the rm program instead of the built-in perl routine.
47
+#
48
+cmd_rm		/bin/rm
49
+
50
+# rsync must be enabled for anything to work. This is the only command that
51
+# must be enabled.
52
+#
53
+cmd_rsync	/usr/bin/rsync
54
+
55
+# Uncomment this to enable remote ssh backups over rsync.
56
+#
57
+cmd_ssh	/usr/bin/ssh
58
+
59
+# Comment this out to disable syslog support.
60
+#
61
+cmd_logger	/usr/bin/logger
62
+
63
+# Uncomment this to specify the path to "du" for disk usage checks.
64
+# If you have an older version of "du", you may also want to check the
65
+# "du_args" parameter below.
66
+#
67
+#cmd_du		/usr/bin/du
68
+
69
+# Uncomment this to specify the path to rsnapshot-diff.
70
+#
71
+#cmd_rsnapshot_diff	/usr/bin/rsnapshot-diff
72
+
73
+# Specify the path to a script (and any optional arguments) to run right
74
+# before rsnapshot syncs files
75
+#
76
+#cmd_preexec	/path/to/preexec/script
77
+
78
+# Specify the path to a script (and any optional arguments) to run right
79
+# after rsnapshot syncs files
80
+#
81
+#cmd_postexec	/path/to/postexec/script
82
+
83
+# Paths to lvcreate, lvremove, mount and umount commands, for use with
84
+# Linux LVMs.
85
+#
86
+#linux_lvm_cmd_lvcreate	/sbin/lvcreate
87
+#linux_lvm_cmd_lvremove	/sbin/lvremove
88
+#linux_lvm_cmd_mount	/bin/mount
89
+#linux_lvm_cmd_umount	/bin/umount
90
+
91
+#########################################
92
+#           BACKUP INTERVALS            #
93
+# Must be unique and in ascending order #
94
+# i.e. hourly, daily, weekly, etc.      #
95
+#########################################
96
+
97
+#retain		hourly	6
98
+retain		daily	7
99
+retain		weekly	4
100
+retain		monthly	12
101
+
102
+############################################
103
+#              GLOBAL OPTIONS              #
104
+# All are optional, with sensible defaults #
105
+############################################
106
+
107
+# Verbose level, 1 through 5.
108
+# 1     Quiet           Print fatal errors only
109
+# 2     Default         Print errors and warnings only
110
+# 3     Verbose         Show equivalent shell commands being executed
111
+# 4     Extra Verbose   Show extra verbose information
112
+# 5     Debug mode      Everything
113
+#
114
+verbose		2
115
+
116
+# Same as "verbose" above, but controls the amount of data sent to the
117
+# logfile, if one is being used. The default is 3.
118
+#
119
+loglevel	3
120
+
121
+# If you enable this, data will be written to the file you specify. The
122
+# amount of data written is controlled by the "loglevel" parameter.
123
+#
124
+#logfile	/var/log/rsnapshot.log
125
+
126
+# If enabled, rsnapshot will write a lockfile to prevent two instances
127
+# from running simultaneously (and messing up the snapshot_root).
128
+# If you enable this, make sure the lockfile directory is not world
129
+# writable. Otherwise anyone can prevent the program from running.
130
+#
131
+lockfile	/var/run/rsnapshot.pid
132
+
133
+# By default, rsnapshot check lockfile, check if PID is running
134
+# and if not, consider lockfile as stale, then start
135
+# Enabling this stop rsnapshot if PID in lockfile is not running
136
+#
137
+#stop_on_stale_lockfile		0
138
+
139
+# Default rsync args. All rsync commands have at least these options set.
140
+#
141
+#rsync_short_args	-a
142
+#rsync_long_args	--delete --numeric-ids --relative --delete-excluded
143
+
144
+# ssh has no args passed by default, but you can specify some here.
145
+#
146
+#ssh_args	-p 22
147
+
148
+# Default arguments for the "du" program (for disk space reporting).
149
+# The GNU version of "du" is preferred. See the man page for more details.
150
+# If your version of "du" doesn't support the -h flag, try -k flag instead.
151
+#
152
+#du_args	-csh
153
+
154
+# If this is enabled, rsync won't span filesystem partitions within a
155
+# backup point. This essentially passes the -x option to rsync.
156
+# The default is 0 (off).
157
+#
158
+#one_fs		0
159
+
160
+# The include and exclude parameters, if enabled, simply get passed directly
161
+# to rsync. If you have multiple include/exclude patterns, put each one on a
162
+# separate line. Please look up the --include and --exclude options in the
163
+# rsync man page for more details on how to specify file name patterns. 
164
+# 
165
+#include	???
166
+#include	???
167
+#exclude	???
168
+#exclude	???
169
+
170
+# The include_file and exclude_file parameters, if enabled, simply get
171
+# passed directly to rsync. Please look up the --include-from and
172
+# --exclude-from options in the rsync man page for more details.
173
+#
174
+#include_file	/path/to/include/file
175
+#exclude_file	/path/to/exclude/file
176
+
177
+# If your version of rsync supports --link-dest, consider enable this.
178
+# This is the best way to support special files (FIFOs, etc) cross-platform.
179
+# The default is 0 (off).
180
+#
181
+#link_dest	0
182
+
183
+# When sync_first is enabled, it changes the default behaviour of rsnapshot.
184
+# Normally, when rsnapshot is called with its lowest interval
185
+# (i.e.: "rsnapshot hourly"), it will sync files AND rotate the lowest
186
+# intervals. With sync_first enabled, "rsnapshot sync" handles the file sync,
187
+# and all interval calls simply rotate files. See the man page for more
188
+# details. The default is 0 (off).
189
+#
190
+#sync_first	0
191
+
192
+# If enabled, rsnapshot will move the oldest directory for each interval
193
+# to [interval_name].delete, then it will remove the lockfile and delete
194
+# that directory just before it exits. The default is 0 (off).
195
+#
196
+#use_lazy_deletes	0
197
+
198
+# Number of rsync re-tries. If you experience any network problems or
199
+# network card issues that tend to cause ssh to crap-out with
200
+# "Corrupted MAC on input" errors, for example, set this to a non-zero
201
+# value to have the rsync operation re-tried
202
+#
203
+#rsync_numtries 0
204
+
205
+# LVM parameters. Used to backup with creating lvm snapshot before backup
206
+# and removing it after. This should ensure consistency of data in some special
207
+# cases
208
+#
209
+# LVM snapshot(s) size (lvcreate --size option).
210
+#
211
+#linux_lvm_snapshotsize	100M
212
+
213
+# Name to be used when creating the LVM logical volume snapshot(s).
214
+#
215
+#linux_lvm_snapshotname	rsnapshot
216
+
217
+# Path to the LVM Volume Groups.
218
+#
219
+#linux_lvm_vgpath	/dev
220
+
221
+# Mount point to use to temporarily mount the snapshot(s).
222
+#
223
+#linux_lvm_mountpath	/path/to/mount/lvm/snapshot/during/backup
224
+
225
+###############################
226
+### BACKUP POINTS / SCRIPTS ###
227
+###############################
228
+
229
+# LOCALHOST
230
+#backup	/home/		localhost/
231
+#backup	/etc/		localhost/
232
+#backup	/usr/local/	localhost/
233
+#backup	/var/log/rsnapshot		localhost/
234
+#backup	/etc/passwd	localhost/
235
+#backup	/home/foo/My Documents/		localhost/
236
+#backup	/foo/bar/	localhost/	one_fs=1, rsync_short_args=-urltvpog
237
+#backup_script	/usr/local/bin/backup_pgsql.sh	localhost/postgres/
238
+# You must set linux_lvm_* parameters below before using lvm snapshots
239
+#backup	lvm://vg0/xen-home/	lvm-vg0/xen-home/
240
+
241
+# EXAMPLE.COM
242
+#backup_script	/bin/date "+ backup of example.com started at %c"	unused1
243
+#backup	root@example.com:/home/	example.com/	+rsync_long_args=--bwlimit=16,exclude=core
244
+#backup	root@example.com:/etc/	example.com/	exclude=mtab,exclude=core
245
+#backup_script	ssh root@example.com "mysqldump -A > /var/db/dump/mysql.sql"	unused2
246
+#backup	root@example.com:/var/db/dump/	example.com/
247
+#backup_script	/bin/date	"+ backup of example.com ended at %c"	unused9
248
+
249
+# CVS.SOURCEFORGE.NET
250
+#backup_script	/usr/local/bin/backup_rsnapshot_cvsroot.sh	rsnapshot.cvs.sourceforge.net/
251
+
252
+# RSYNC.SAMBA.ORG
253
+#backup	rsync://rsync.samba.org/rsyncftp/	rsync.samba.org/rsyncftp/
254
+
255
+backup_script	/bin/date "+ backup started at %c" | /usr/bin/tee date	backup_start_date
256
+
257
+include_conf	/etc/rsnapshot/user_backup.conf
258
+
259
+backup_script	/bin/date "+ backup ended at %c" | /usr/bin/tee date	backup_end_date
260
+

+ 11
- 0
rsnapshot/config/rsnapshot.cron.conf Vedi File

@@ -0,0 +1,11 @@
1
+# This is a sample cron file for rsnapshot.
2
+# The values used correspond to the examples in /etc/rsnapshot.conf.
3
+# There you can also set the backup points and many other things.
4
+#
5
+# To activate this cron file you have to uncomment the lines below.
6
+# Feel free to adapt it to your needs.
7
+
8
+# 00 */4		* * *		root	/usr/bin/rsnapshot hourly
9
+ 00  3  	* * *		root	/usr/bin/rsnapshot daily
10
+ 50  2  	* * 1		root	/usr/bin/rsnapshot weekly
11
+ 55  2  	1 * *		root	/usr/bin/rsnapshot monthly

+ 19
- 0
rsnapshot/config/ssmtp.conf Vedi File

@@ -0,0 +1,19 @@
1
+# Configuartion file for sSMTP sendmail
2
+
3
+# The person who gets all mail for userids < 1000
4
+# Make this empty to disable rewriting.
5
+root=SSMTP_ROOT
6
+
7
+# We want to use this with an exim container. Link these
8
+# so that that container will be reachable as 'exim' in
9
+# this container.
10
+mailhub=SSMTP_MAILHUB
11
+
12
+# Where will the mail seem to come from?
13
+rewriteDomain=SSMTP_MAILDOMAIN
14
+
15
+# The full hostname
16
+#hostname=
17
+
18
+# Are users allowed to set their own From: address? (YES/NO)
19
+FromLineOverride=YES

+ 7
- 0
rsnapshot/run.sh Vedi File

@@ -0,0 +1,7 @@
1
+#! /usr/bin/env bash
2
+
3
+. /common.sh
4
+
5
+replace_files
6
+
7
+cron -f

+ 3
- 0
rsnapshot/vars-files Vedi File

@@ -0,0 +1,3 @@
1
+ssmtp.conf /etc/ssmtp/ssmtp.conf
2
+rsnapshot.cron.conf /etc/cron.d/rsnapshot
3
+rsnapshot.conf /etc/rsnapshot.conf

+ 3
- 0
rsnapshot/vars-vars Vedi File

@@ -0,0 +1,3 @@
1
+SSMTP_ROOT
2
+SSMTP_MAILHUB
3
+SSMTP_MAILDOMAIN

+ 7
- 0
update_vars.sh Vedi File

@@ -0,0 +1,7 @@
1
+#! /usr/bin/env sh
2
+
3
+vars=$(cat env | cut -d= -f1)
4
+for docker in rsnapshot
5
+do
6
+  echo "${vars}" > "./${docker}/vars-vars"
7
+done

Loading…
Annulla
Salva