Skip to content

Commit e861a65

Browse files
committed
Replace Attic with Borg. #2
1 parent e6b0eba commit e861a65

15 files changed

+62
-50
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
# config files
44
conf.d/*
5-
!conf.d/*.example
5+
!conf.d/example-*.sh
6+
!conf.d/example-excludes.txt
67

78
# IntelliJ
89
*.iml
910
.idea/
11+
12+
_deploy*.sh

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Simple backup scripts
22

3-
This is a collections of scripts, which automate the backup process of Linux server using [Attic](https://attic-backup.org/), a deduplicating backup tool.
3+
This is a collections of scripts, which automate the backup process of Linux server using [Borg](https://borgbackup.readthedocs.io), a deduplicating backup tool.
44

55
The starting point is `backup.sh`, which works in following way:
66
* The scripts starts.
77
* **premount** scripts are executed.
8-
* If Attic repository is remote, it's mounted.
8+
* If Borg repository is remote, it's mounted.
99
* **predump** scripts are executed.
10-
* Attic creates backup point for each mountpoint defined in *general.sh*.
10+
* Borg creates backup point for each mountpoint defined in *general.sh*.
1111
* **postdump** scripts are executed.
1212
* If the repository is remote, it's unmounted.
1313
* **postmount** scripts are executed.
@@ -29,16 +29,16 @@ The plain file dump doesn't guarantee the database consistency. To address this
2929

3030
Scripts dumps first 512 bytes for each drive defined in `PREMOUNT_MBR_PHYSICAL_DEVICES`. This area contains the MBR and partition table.
3131

32-
## Copying Attic repository to secondary location
32+
## Copying Borg repository to secondary location
3333

34-
`copy_attic_repository_rsync` side script can be used to copy the Attic repository to secondary remote location, which increases survivability in case of storage failure.
34+
`copy_borg_repository_rsync` side script can be used to copy the repository to secondary remote location, which increases survivability in case of storage failure.
3535

3636
## Installation
3737

3838
* Install required packages:
3939

4040
```bash
41-
aptitude install sshfs attic rsync lbzip2
41+
aptitude install sshfs borgbackup rsync lbzip2
4242
```
4343

4444
* Checkout the repository, preferable to *root*'s home directory:
@@ -50,18 +50,18 @@ git clone https://github.com/1connect/backup-scripts
5050
* Go to *backup-scripts/conf.d* directory. There are several *.example* files. To enable the module, copy it's configuration file to it's proper name:
5151

5252
```
53-
cp general.sh.example general.sh
53+
cp example-general.sh general.sh
5454
```
5555

56-
You shouldn't change name of the *.example* files, because you'll run into conflicts when you decide to pull the new version from the repository. *general.sh* is main configuration file, you should have it enabled and configured.
56+
You shouldn't change name of the *example-* files, because you'll run into conflicts when you decide to pull the new version from the repository. *general.sh* is main configuration file, you should have it enabled and configured.
5757

5858
* After you're done with configuration, run the *backup.sh* script in verbose mode:
5959

6060
```
6161
~/backup-scripts/backup.sh -v
6262
```
6363

64-
First, it runs *premount* and *predump* modules. Then it initializes the Attic repository. You shouldn't set any password, because you won't be able to provide it during automated backup.
64+
First, it runs *premount* and *predump* modules. Then it initializes the Borg repository. You shouldn't set any password, because you won't be able to provide it during automated backup.
6565

6666
The very first run deduplicates your whole filesystem, it'll take long. The subsequent runs are much faster.
6767

@@ -78,18 +78,15 @@ The very first run deduplicates your whole filesystem, it'll take long. The subs
7878
List list existing backups and choose the one which suits your needs the best.
7979

8080
```
81-
attic list /my/backup/storage/myhostname/repository.attic/
81+
borg list /my/backup/storage/myhostname/repository.borg/
8282
```
8383

84-
Then access the files. The most convenient way is to use Attic *mount* feature:
84+
Then access the files. The most convenient way is to use Borg *mount* feature:
8585

8686
```
87-
attic mount /my/backup/storage/myhostname/repository.attic::{backup point} /tmp/restore
87+
borg mount /my/backup/storage/myhostname/repository.borg::{backup point} /tmp/restore
8888
```
8989

90-
**Warning!** Because of bug present in Attic, you always have to provide the full path to the repository.
91-
92-
9390
### Restore MongoDB
9491

9592
These commands will erase the content from the database and replace it with version from the backup.
@@ -101,7 +98,7 @@ mongorestore --db {database} --drop {database}
10198

10299
## Encryption keys
103100

104-
If you enabled encryption, Attic stores the encryption keys in `~/.attic/keys`. Remember to backup them separately; you won't be able to use your backup if you loose them!
101+
If you enabled encryption, Borg stores the encryption keys in `~/.config/borg/keys`. All keys are encrypted with password `backup`. The key to the security is to hold them in secure location. Remember to backup them separately; you won't be able to use your backup if you loose them!
105102

106103

107104

backup.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fi
8989

9090
run_sidescripts premount
9191

92-
ATTIC_OPTIONS=""
92+
BORG_OPTIONS=""
9393

9494
if [[ ${SIDE_SCRIPTS_ONLY} -eq 0 ]]
9595
then
@@ -103,18 +103,20 @@ then
103103

104104
out="${DST_LOCAL_LOCATION}/${HOSTNAME}"
105105
${ECHO} mkdir -p ${out}
106-
out+='/repository.attic'
107-
export ATTIC_REPOSITORY_PATH="${out}"
106+
out+='/repository.borg'
107+
export BORG_REPOSITORY_PATH="${out}"
108108

109109
if [[ "${VERBOSE}" -ne 0 ]]
110110
then
111-
ATTIC_OPTIONS+=" --stats"
112-
echo "** starting attic backup"
111+
BORG_OPTIONS+=" --stats"
112+
echo "** starting Borg backup"
113113
fi
114114

115-
if [ ! -d ${ATTIC_REPOSITORY_PATH} ]
115+
export BORG_PASSPHRASE='backup'
116+
117+
if [ ! -d ${BORG_REPOSITORY_PATH} ]
116118
then
117-
${ECHO} attic init --encryption=${ENCRYPTION_MODE} ${ATTIC_REPOSITORY_PATH}
119+
${ECHO} borg init --encryption=${ENCRYPTION_MODE} ${BORG_REPOSITORY_PATH}
118120
fi
119121

120122
for directory in ${SRC_DIRECTORIES}
@@ -144,10 +146,10 @@ then
144146
fi
145147
done
146148

147-
${ECHO} ionice -c3 -t attic create ${ATTIC_OPTIONS} ${ATTIC_REPOSITORY_PATH}::$(full_date)-${prefix} ${directory} ${EXCLUDE_LIST}
149+
${ECHO} ionice -c3 -t borg create ${BORG_OPTIONS} ${BORG_REPOSITORY_PATH}::$(full_date)-${prefix} ${directory} ${EXCLUDE_LIST}
148150
done
149151

150-
${ECHO} ionice -c3 -t attic prune ${ATTIC_OPTIONS} ${ATTIC_REPOSITORY_PATH} ${ATTIC_PRUNE_AGES}
152+
${ECHO} ionice -c3 -t borg prune ${BORG_OPTIONS} ${BORG_REPOSITORY_PATH} ${BORG_PRUNE_AGES}
151153

152154
run_sidescripts postdump
153155

conf.d/copy_attic_repository_rsync.sh.example

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
export POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_ENABLED=1
4+
5+
export POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_USER=backup
6+
export POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_HOST=backup.example.org
7+
export POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_PORT=22
8+
9+
export POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_PATH=/data/backup
File renamed without changes.
File renamed without changes.

conf.d/general.sh.example renamed to conf.d/example-general.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ export DST_LOCAL_LOCATION='/tmp/backup'
1717

1818
# You should set whether you want to encrypt your backup
1919
# valid values are: none, keyfile
20+
# don't use repokey mode since standard password 'backup' is provided to Borg calls
2021
#export ENCRYPTION_MODE=none
2122
export ENCRYPTION_MODE=keyfile
2223

2324
# they should match with the filesystem mount points
2425
export SRC_DIRECTORIES="/ /boot"
2526

26-
export ATTIC_EXCLUDE_FILE="excludes.txt"
27+
export BORG_EXCLUDE_FILE="excludes.txt"
2728

28-
export ATTIC_PRUNE_AGES="--keep-within=14d --keep-weekly=8 --keep-monthly=6"
29+
export BORG_PRUNE_AGES="--keep-within=14d --keep-weekly=8 --keep-monthly=6"
2930

3031

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

migrate_config_borg.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
cd conf.d
4+
5+
if [ -f copy_attic_repository_rsync.sh ]; then
6+
mv copy_attic_repository_rsync.sh copy_borg_repository_rsync.sh
7+
fi
8+
9+
sed -i -- 's/ATTIC/BORG/g' *.sh

postdump.d/50copy_attic_repository_rsync.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
RSYNC_OPTIONS="-rzx --safe-links --delete"
4+
5+
[[ ${VERBOSE} -ne 0 ]] && RSYNC_OPTIONS+=" --progress --stats --verbose -h "
6+
7+
userAndHost="${POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_USER}@${POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_HOST}"
8+
outputDirectory="${POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_PATH}/${HOSTNAME}"
9+
10+
ssh -p ${POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_PORT} ${userAndHost} "mkdir -p ${outputDirectory}"
11+
12+
rsync ${RSYNC_OPTIONS} -e "ssh -p ${POSTDUMP_COPY_BORG_REPOSITORY_RSYNC_SSH_PORT}" ${BORG_REPOSITORY_PATH} ${userAndHost}:${outputDirectory}
13+

0 commit comments

Comments
 (0)