Skip to content

Commit 78dc929

Browse files
committed
First version of the offsite-replication script.
It works with FTP source and EncFS volume at SSH destination only.
1 parent 50e16fc commit 78dc929

File tree

2 files changed

+898
-0
lines changed

2 files changed

+898
-0
lines changed

rsync/offsite-replication/README.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Script to perform an off-site replication via rsync and EncFS
2+
=============================================================
3+
4+
Description
5+
-----------
6+
7+
This script aims to replicate data from server A to server B.
8+
9+
Because it was created for simple, low storage capacity servers, it uses AutoFS to automatically mount remote source and destination.
10+
Because destination server might totally not be under our control, it uses a [EncFS](https://vgough.github.io/encfs/) volume for the destination.
11+
12+
At the moment:
13+
* source is a FTP server
14+
* destination a SSH server.
15+
* using rsync via [my *one-way-mirror* rsync script](https://github.com/C-Duv/sysadmin-scripts/tree/master/rsync/one-way-mirror) to perform the data transfer.
16+
17+
TODO-list:
18+
* Support local, already mounted path
19+
* Support SSH as source
20+
* Support FTP as destination
21+
* Support EncFS volume as source
22+
23+
Installation
24+
------------
25+
26+
Usage:
27+
```Shell
28+
encfs-rsync-from-autofs-mounted-path_installer.sh [-c config_file]
29+
```
30+
31+
If option `-c` is not set, script will use `offsite_replication.cfg` as the name of the configuration file.
32+
33+
If _config_file_ does not exists, a blank configuration file will be created and script will exit.
34+
35+
Configuration file example:
36+
37+
# Path where to install
38+
CFG_INSTALL_PATH="/root/scripts/offsite_replication"
39+
40+
41+
# Infos to access source server
42+
SOURCE_SERVER_TYPE="FTP" # (Script only supports FTP source)
43+
SOURCE_SERVER_NAME="source_server" # Friendly name
44+
SOURCE_SERVER_HOST="a.b.c.d" # IP or host or FQDN
45+
SOURCE_SERVER_PORT="21"
46+
SOURCE_SERVER_LOGIN="$(hostname)"
47+
SOURCE_SERVER_PASSWORD='secret'
48+
SOURCE_SERVER_PATH="/" # Path, on the remote server, where to fetch files
49+
50+
# Infos to access destination server
51+
DESTINATION_SERVER_TYPE="SSH" # (Script only supports SSH destination)
52+
DESTINATION_SERVER_NAME="remote_site"
53+
DESTINATION_SERVER_HOST="destination_server.domain.tld" # IP or host or FQDN
54+
DESTINATION_SERVER_PORT="22"
55+
DESTINATION_SERVER_LOGIN="$(hostname)"
56+
DESTINATION_SERVER_PASSWORD='' # No password means SSH key will be used
57+
DESTINATION_SERVER_PATH="/mnt/replications/foobar" # Path, on the remote server, where to replicate files (from source)
58+
59+
60+
## AutoFS
61+
62+
# Path where AutoFS will mount the mounted
63+
CFG_AUTOFS_CONTAINER="/mnt/autofs"
64+
65+
# Name of the AutoFS mount corresponding to the source (cannot contain spaces)
66+
CFG_AUTOFS_SOURCE_MOUNT_NAME="${SOURCE_SERVER_NAME}"
67+
CFG_AUTOFS_SOURCE_MOUNT_PATH="${CFG_AUTOFS_CONTAINER}/${CFG_AUTOFS_SOURCE_MOUNT_NAME}"
68+
69+
# Name of the AutoFS mount corresponding to the destination (cannot contain spaces)
70+
CFG_AUTOFS_DESTINATION_MOUNT_NAME="offsite_replication"
71+
CFG_AUTOFS_DESTINATION_MOUNT_PATH="${CFG_AUTOFS_CONTAINER}/${CFG_AUTOFS_DESTINATION_MOUNT_NAME}"
72+
73+
## /AutoFS
74+
75+
76+
## EncFS
77+
78+
#NOTE: Left for future improvements: EncFS source volume:
79+
#CFG_ENCFS_SOURCE_ENCRYPTION_PASSWORD='secret'
80+
#CFG_ENCFS_SOURCE_ENCRYPTED_VOLUME_SUBPATH="backups"
81+
#CFG_ENCFS_SOURCE_MOUNT_POINT="/mnt/${SOURCE_SERVER_NAME}-encfs_access"
82+
83+
# EncFS encrypted volume password
84+
CFG_ENCFS_DESTINATION_ENCRYPTION_PASSWORD='secret'
85+
86+
# Path to EncFS encrypted volume (relative path, relative to $DESTINATION_SERVER_PATH)
87+
CFG_ENCFS_DESTINATION_ENCRYPTED_VOLUME_SUBPATH="foobar"
88+
89+
# Path where EncFS will mount the directory
90+
CFG_ENCFS_DESTINATION_MOUNT_POINT="/mnt/offsite_replication-encfs_access"
91+
92+
## /EncFS
93+
94+
95+
## Scripts
96+
97+
CFG_SCRIPTS_PATH="${CFG_INSTALL_PATH}"
98+
CFG_SCRIPTS_LOGPATH="/var/log/offsite_replication"
99+
100+
# one-way-mirror script : https://github.com/C-Duv/sysadmin-scripts/tree/master/rsync/one-way-mirror
101+
CFG_SCRIPTS_ONEWAYMIRROR_DOWNLOAD_URL="https://raw.githubusercontent.com/C-Duv/sysadmin-scripts/master/rsync/one-way-mirror/one-way-mirror-rsync.sh"
102+
103+
# Schedule of replication
104+
CFG_SCRIPTS_TRANSFEROPERATOR_CRON_TIMESPEC="0 20 * * *"
105+
106+
107+
Manual transfer
108+
---------------
109+
110+
Main script file is `encfs+script_wrapper.sh`. It needs the configuration file (will look for `offsite_replication.cfg` if none specified):
111+
112+
```Shell
113+
encfs+script_wrapper.sh [-c config_file] wrapped_script
114+
```
115+
116+
This script is said to be a *wrapper* because it wraps any script (typically a script that does data transfer) with EncFS mounting and unmounting.
117+
118+
An effort is made by this script to support concurrent run: but `wrapped_script` must support it.
119+
120+
`wrapped_script` is run in the same context/scope as `encfs+script_wrapper.sh` so it has access to the same (configuration) variables.
121+
122+
123+
Scheduled transfer
124+
------------------
125+
126+
Installer adds a crontab entry in `/etc/cron.d` that runs `transfer.sh` (via `encfs+script_wrapper.sh`) according to `$CFG_SCRIPTS_TRANSFEROPERATOR_CRON_TIMESPEC`.
127+
128+
129+
Transfer implementation
130+
-----------------------
131+
132+
I am currently using [my *one-way-mirror* rsync script](https://github.com/C-Duv/sysadmin-scripts/tree/master/rsync/one-way-mirror) to perform the transfer.
133+
It is called by `transfer.sh` which is itself wrapped around EncFS mounting/unmounting thanks to `encfs+script_wrapper.sh`.

0 commit comments

Comments
 (0)