aboutsummaryrefslogtreecommitdiff
path: root/content/operations/rclone.md
blob: 1352aafcf956dc4ef203a491f13c66d9f1a11dd1 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
---
title: "rclone"
description: "rclone"
weight: 20
sort_by: "weight"
extra:
  parent: 'operations/sauvegardes.md'
---

Script de backup brut, on planifie une approche plus élégante à l'avenir :

```
#!/bin/bash

cd $(dirname $0)

if [ "$(hostname)" != "io" ]; then
	echo "Please run this script on io"
	exit 1
fi

if [ ! -d "buckets" ]; then
	btrfs subvolume create $(pwd)/buckets
fi


AK=$1
SK=$2

function gctl {
	docker exec garage /garage $@
}

gctl status
BUCKETS=$(gctl bucket list | tail -n +2 | cut -d " " -f 3 | cut -d "," -f 1)

for BUCKET in $BUCKETS; do
	case $BUCKET in
		*backup*)
			echo "Skipping $BUCKET (not doing backup of backup)"
			;;
		*cache*)
			echo "Skipping $BUCKET (not doing backup of cache)"
			;;
		*)
			echo "Backing up $BUCKET"

			if [ ! -d $(pwd)/buckets/$BUCKET ]; then
				mkdir $(pwd)/buckets/$BUCKET
			fi

			gctl bucket allow --key $AK --read $BUCKET
			rclone sync --s3-endpoint http://localhost:3900 \
				--s3-access-key-id $AK \
				--s3-secret-access-key $SK \
				--s3-region garage \
				--s3-force-path-style \
				--transfers 32 \
				--fast-list \
				--stats-one-line \
				--stats 10s \
				--stats-log-level NOTICE \
		       		:s3:$BUCKET $(pwd)/buckets/$BUCKET
			;;
	esac
done

# Remove duplicates
#duperemove -dAr $(pwd)/buckets

if [ ! -d "$(pwd)/snapshots" ]; then
	mkdir snapshots
fi

SNAPSHOT=$(pwd)/snapshots/buckets-$(date +%F)
echo "Making snapshot: $SNAPSHOT"
btrfs subvolume snapshot $(pwd)/buckets $SNAPSHOT
```