Skip to content

Commit e5e0a12

Browse files
fix(tuto): update tutorial duplicity (#4890)
* fix(tuto): fix script duplicity * fix(tuto): fix date * fix(tuto): wording * Update tutorials/backup-dedicated-server-s3-duplicity/index.mdx Co-authored-by: ldecarvalho-doc <[email protected]> --------- Co-authored-by: ldecarvalho-doc <[email protected]>
1 parent c83a4c5 commit e5e0a12

File tree

1 file changed

+64
-94
lines changed
  • tutorials/backup-dedicated-server-s3-duplicity

1 file changed

+64
-94
lines changed

tutorials/backup-dedicated-server-s3-duplicity/index.mdx

Lines changed: 64 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tags: duplicity backup gpg s3
99
categories:
1010
- object-storage
1111
dates:
12-
validation: 2024-10-15
12+
validation: 2025-04-24
1313
posted: 2018-10-13
1414
---
1515

@@ -52,13 +52,8 @@ In this step, we install the various software needed. As well as installing Dupl
5252
Run the following command to update the APT package manager, upgrade the software already installed on the server and download and install Duplicity and the other required software:
5353

5454
```bash
55-
apt update && apt upgrade
56-
apt install -y python3-boto python3-pip haveged gettext librsync-dev
57-
wget https://gitlab.com/duplicity/duplicity/-/archive/rel.2.1.2/duplicity-rel.2.1.2.tar.gz
58-
tar xaf duplicity-rel.2.1.2.tar.gz
59-
cd duplicity-rel.2.1.2/
60-
pip3 install -r requirements.txt
61-
python3 setup.py install
55+
sudo apt update && sudo apt upgrade -y
56+
sudo apt install -y python3-pip gnupg2 haveged duplicity
6257
```
6358

6459
## Creating a GPG key
@@ -164,29 +159,21 @@ As everything is installed and ready, we will now configure and script our inter
164159
mkdir -p /var/log/duplicity
165160
touch /var/log/duplicity/logfile{.log,-recent.log}
166161
```
167-
2. Add the following lines to `.scw-configrc`. Make sure you replace the necessary values with the details of your Scaleway API key, Object Storage bucket, and GPG key. You also need to enter a path to the desired backup folder:
162+
2. Create a config file `~/.scw-backup.env`. Make sure you replace the necessary values with the details of your Scaleway API key, Object Storage bucket, and GPG key. You also need to enter a path to the folder you want to back up:
168163
```bash
169164
# Scaleway credentials keys
170165
export AWS_ACCESS_KEY_ID="<SCALEWAY ACCESS KEY>"
171-
export AWS_SECRET_ACCESS_KEY="<SCALEWAY SECRET ACCESS KEY>"
166+
export AWS_SECRET_ACCESS_KEY="<SCALEWAY SECRET KEY>"
172167

173-
export SCW_REGION="<REGION OF YOUR BUCKET>"
168+
export SCW_REGION="<REGION OF YOUR BUCKET>s"
174169
export SCW_ENDPOINT_URL="https://s3.${SCW_REGION}.scw.cloud"
175-
176-
# set SCW_BUCKET as follows for duplicity < 0.8.23
177-
# for higher versions, see below
178-
# export SCW_BUCKET="s3://s3.${SCW_REGION}.scw.cloud/<NAME OF YOUR BUCKET>"
179-
180-
# set the next two variables for duplicity >= 0.8.23
181-
# it uses the boto3 library, which uses a different naming scheme for bucket names
182-
export SCW_BUCKET="s3://<NAME OF YOUR BUCKET>"
183-
170+
export SCW_BUCKET="s3://<YOUR BUCKET NAME>"
184171
# GPG Key information
185-
export PASSPHRASE="<YOUR GPG KEY PASSPHRASE>"
186-
export GPG_FINGERPRINT="<YOUR GPG KEY FINGERPRINT>"
172+
export GPG_FINGERPRINT="<YOUR GPG KEY PASSPHRASE>"
173+
export PASSPHRASE="<YOUR GPG KEY FINGERPRINT>"
187174

188175
# Folder to backup
189-
export SOURCE="<PATH TO FOLDER TO BACKUP>"
176+
export SOURCE="/path/to/backup"
190177

191178
# Will keep backup up to 1 month
192179
export KEEP_BACKUP_TIME="1M"
@@ -197,13 +184,6 @@ As everything is installed and ready, we will now configure and script our inter
197184
# Log files
198185
export LOGFILE_RECENT="/var/log/duplicity/logfile-recent.log"
199186
export LOGFILE="/var/log/duplicity/logfile.log"
200-
201-
log () {
202-
date=`date +%Y-%m-%d`
203-
hour=`date +%H:%M:%S`
204-
echo "$date $hour $*" >> ${LOGFILE_RECENT}
205-
}
206-
export -f log
207187
```
208188
209189
The backup policy described here makes a full backup every 10 days and removes all backups older than one month.
@@ -214,41 +194,39 @@ Using the configuration and Duplicity, we automatize the backup process with the
214194
215195
1. Copy the following script to `scw-backups.sh`:
216196
```bash
217-
#!/bin/bash
218-
source <FULL PATH TO>/.scw-configrc
219-
220-
currently_backuping=$(ps -ef | grep duplicity | grep python | wc -l)
221-
222-
if [ $currently_backuping -eq 0 ]; then
223-
# Clear the recent log file
224-
cat /dev/null > ${LOGFILE_RECENT}
225-
226-
log ">>> removing old backups"
227-
duplicity remove-older-than \
228-
--s3-endpoint-url ${SCW_ENDPOINT_URL} \
229-
--s3-region-name ${SCW_REGION} \
230-
${KEEP_BACKUP_TIME} ${SCW_BUCKET} >> ${LOGFILE_RECENT} 2>&1
231-
232-
# duplicity >= 0.8.23
233-
# determine S3_ENDPOINT_URL for scaleway
234-
S3_ENDPOINT_URL="https://s3.${S3_REGION_NAME}.scw.cloud"
235-
236-
log ">>> creating and uploading backup to Scaleway Glacier"
237-
duplicity \
238-
incr --full-if-older-than ${FULL_BACKUP_TIME} \
239-
--asynchronous-upload \
240-
--s3-use-glacier \
241-
--s3-endpoint-url ${SCW_ENDPOINT_URL} \
242-
--s3-region-name ${SCW_REGION} \
243-
--encrypt-key=${GPG_FINGERPRINT} \
244-
--sign-key=${GPG_FINGERPRINT} \
245-
${SOURCE} ${SCW_BUCKET} >> ${LOGFILE_RECENT} 2>&1
246-
247-
cat ${LOGFILE_RECENT} >> ${LOGFILE}
248-
fi
197+
#!/bin/bash
198+
source ~/.scw-backup.env
199+
200+
mkdir -p /var/log/duplicity
201+
touch "$LOGFILE_RECENT" "$LOGFILE"
202+
203+
currently_backuping=$(pgrep -f duplicity | wc -l)
204+
205+
if [ "$currently_backuping" -eq 0 ]; then
206+
echo "$(date '+%F %T') >>> Removing old backups" >> "$LOGFILE_RECENT"
207+
duplicity remove-older-than "$KEEP_BACKUP_TIME" "$SCW_BUCKET" \
208+
--s3-endpoint-url "$SCW_ENDPOINT_URL" \
209+
--s3-region-name "$SCW_REGION" >> "$LOGFILE_RECENT" 2>&1
210+
211+
echo "$(date '+%F %T') >>> Running backup" >> "$LOGFILE_RECENT"
212+
duplicity \
213+
incr --full-if-older-than "$FULL_BACKUP_TIME" \
214+
--asynchronous-upload \
215+
--encrypt-key="$GPG_FINGERPRINT" \
216+
--sign-key="$GPG_FINGERPRINT" \
217+
--s3-endpoint-url "$SCW_ENDPOINT_URL" \
218+
--s3-region-name "$SCW_REGION" \
219+
"$SOURCE" "$SCW_BUCKET" >> "$LOGFILE_RECENT" 2>&1
220+
221+
cat "$LOGFILE_RECENT" >> "$LOGFILE"
222+
fi
249223
```
250224
251-
2. Run the script `./scw-backups.sh` to make sure the configuration is correctly set. Check the Object Storage bucket on the [Scaleway console](https://console.scaleway.com) to see the backup files, or examine the logs with the following command:
225+
2. Make the script executable:
226+
```bash
227+
chmod +x ~/scw-backup.sh
228+
```
229+
3. Run the script `./scw-backups.sh` to make sure the configuration is correctly set. Check the Object Storage bucket on the [Scaleway console](https://console.scaleway.com) to see the backup files, or examine the logs with the following command:
252230
```bash
253231
cat /var/log/duplicity/logfile-recent.log
254232
```
@@ -260,39 +238,31 @@ Duplicity also allows you to recover a backup. We will create a script to make t
260238
1. Add the following script to `scw-restore.sh`:
261239
```bash
262240
#!/bin/bash
263-
source <FULL PATH TO>/.scw-configrc
264-
265-
if [ $# -lt 2 ]; then
266-
echo -e "Usage $0 <time or delta> [file to restore] <restore to>
267-
Exemple:
268-
\t$ $0 2018-7-21 recovery/ ## recovers * from closest backup to date
269-
\t$ $0 0D secret data/ ## recovers most recent file nammed 'secret'";
270-
exit; fi
271-
272-
if [ $# -eq 2 ]; then
273-
duplicity \
274-
--s3-endpoint-url ${SCW_ENDPOINT_URL} \
275-
--s3-region-name ${SCW_REGION} \
276-
--time $1 \
277-
${SCW_BUCKET} $2
278-
fi
279-
280-
if [ $# -eq 3 ]; then
281-
duplicity \
282-
--s3-endpoint-url ${SCW_ENDPOINT_URL} \
283-
--s3-region-name ${SCW_REGION} \
284-
--time $1 \
285-
--file-to-restore $2 \
286-
${SCW_BUCKET} $3
287-
fi
288-
```
289-
2. Recover the data you uploaded in the previous section with the following command:
290-
```bash
291-
./scw-restore.sh 0D /tmp/backup-recovery-test/
241+
source ~/.scw-backup.env
242+
243+
if [ $# -lt 2 ]; then
244+
echo "Usage: $0 <time or delta> [file to restore] <restore dir>"
245+
exit 1
246+
fi
247+
248+
if [ $# -eq 2 ]; then
249+
duplicity \
250+
--s3-endpoint-url "$SCW_ENDPOINT_URL" \
251+
--s3-region-name "$SCW_REGION" \
252+
--time "$1" \
253+
"$SCW_BUCKET" "$2"
254+
elif [ $# -eq 3 ]; then
255+
duplicity \
256+
--s3-endpoint-url "$SCW_ENDPOINT_URL" \
257+
--s3-region-name "$SCW_REGION" \
258+
--time "$1" \
259+
--file-to-restore "$2" \
260+
"$SCW_BUCKET" "$3"
261+
fi
292262
```
293-
3. Alternatively, recover one specific file with the following format from a backup 5 days ago with:
263+
2. Make the script executable:
294264
```bash
295-
./scw-restore.sh 5D <file> /tmp/backup-recovery-test/
265+
chmod +x ~/scw-restore.sh
296266
```
297267
298268
### Automation of the backups

0 commit comments

Comments
 (0)