Repository: Altinity/clickhouse-backup (go)

Issue:
diff-from backups restore caught in loop
I have a table where I have backed up and pushed to s3 using the diff-from flag. As a test I deleted the 'first' few backups and tried to restore from what was left. 

```
clickhouse@ch-event01-1.sv5:~$ clickhouse-backup list | grep event_alert
- '2021_02_20_00_00_ch-event01.event_alert_local.tar.gz'	2.42 MiB	(created at 20-02-2021 09:22:12)
- '2021_02_20_04_00_ch-event01.event_alert_local.tar.gz'	1.98 MiB	(created at 20-02-2021 09:24:15)
- '2021_02_20_08_00_ch-event01.event_alert_local.tar.gz'	428.49 MiB	(created at 20-02-2021 09:25:40)
- '2021_02_20_12_00_ch-event01.event_alert_local.tar.gz'	170.00 MiB	(created at 21-02-2021 09:00:14)
- '2021_02_20_16_00_ch-event01.event_alert_local.tar.gz'	203.57 MiB	(created at 21-02-2021 09:01:46)
- '2021_02_20_20_00_ch-event01.event_alert_local.tar.gz'	272.38 MiB	(created at 21-02-2021 09:03:00)
- '2021_02_21_00_00_ch-event01.event_alert_local.tar.gz'	172.66 MiB	(created at 21-02-2021 09:04:36)
- '2021_02_21_04_00_ch-event01.event_alert_local.tar.gz'	114.17 MiB	(created at 21-02-2021 09:05:52)
- '2021_02_21_08_00_ch-event01.event_alert_local.tar.gz'	907.23 MiB	(created at 21-02-2021 09:07:20)
- '2021_02_21_12_00_ch-event01.event_alert_local.tar.gz'	174.80 MiB	(created at 21-02-2021 12:31:01)
- '2021_02_21_16_00_ch-event01.event_alert_local.tar.gz'	73.53 MiB	(created at 22-02-2021 09:00:13)
- '2021_02_21_20_00_ch-event01.event_alert_local.tar.gz'	245.51 MiB	(created at 22-02-2021 09:01:42)
- '2021_02_22_00_00_ch-event01.event_alert_local.tar.gz'	2.30 MiB	(created at 22-02-2021 09:03:04)
- '2021_02_22_04_00_ch-event01.event_alert_local.tar.gz'	177.13 MiB	(created at 22-02-2021 09:04:42)
- '2021_02_22_08_00_ch-event01.event_alert_local.tar.gz'	2.02 MiB	(created at 22-02-2021 09:05:59)
clickhouse@ch-event01-1.sv5:~$ clickhouse-backup download 2021_02_22_08_00_ch-event01.event_alert_local
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:08 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:08 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:09 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:09 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:10 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:10 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:10 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:11 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:11 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:12 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:12 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:12 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:13 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:13 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:13 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:14 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:14 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:15 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:15 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:15 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:16 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:16 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:17 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:17 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:17 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:18 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:18 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:19 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:19 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:04:19 Backup '2021_02_22_08_00_ch-event01.event_alert_local' required '2021_02_22_08_00_ch-event01.event_alert_local'. Downloading.
 2.02 MiB / 2.02 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%^C
clickhouse@ch-event01-1.sv5:~$ clickhouse-backup list | grep event_alert
- '2021_02_22_08_00_ch-event01.event_alert_local'	(created at 22-02-2021 12:04:08)
- '2021_02_20_00_00_ch-event01.event_alert_local.tar.gz'	2.42 MiB	(created at 20-02-2021 09:22:12)
- '2021_02_20_04_00_ch-event01.event_alert_local.tar.gz'	1.98 MiB	(created at 20-02-2021 09:24:15)
- '2021_02_20_08_00_ch-event01.event_alert_local.tar.gz'	428.49 MiB	(created at 20-02-2021 09:25:40)
- '2021_02_20_12_00_ch-event01.event_alert_local.tar.gz'	170.00 MiB	(created at 21-02-2021 09:00:14)
- '2021_02_20_16_00_ch-event01.event_alert_local.tar.gz'	203.57 MiB	(created at 21-02-2021 09:01:46)
- '2021_02_20_20_00_ch-event01.event_alert_local.tar.gz'	272.38 MiB	(created at 21-02-2021 09:03:00)
- '2021_02_21_00_00_ch-event01.event_alert_local.tar.gz'	172.66 MiB	(created at 21-02-2021 09:04:36)
- '2021_02_21_04_00_ch-event01.event_alert_local.tar.gz'	114.17 MiB	(created at 21-02-2021 09:05:52)
- '2021_02_21_08_00_ch-event01.event_alert_local.tar.gz'	907.23 MiB	(created at 21-02-2021 09:07:20)
- '2021_02_21_12_00_ch-event01.event_alert_local.tar.gz'	174.80 MiB	(created at 21-02-2021 12:31:01)
- '2021_02_21_16_00_ch-event01.event_alert_local.tar.gz'	73.53 MiB	(created at 22-02-2021 09:00:13)
- '2021_02_21_20_00_ch-event01.event_alert_local.tar.gz'	245.51 MiB	(created at 22-02-2021 09:01:42)
- '2021_02_22_00_00_ch-event01.event_alert_local.tar.gz'	2.30 MiB	(created at 22-02-2021 09:03:04)
- '2021_02_22_04_00_ch-event01.event_alert_local.tar.gz'	177.13 MiB	(created at 22-02-2021 09:04:42)
- '2021_02_22_08_00_ch-event01.event_alert_local.tar.gz'	2.02 MiB	(created at 22-02-2021 09:05:59)
clickhouse@ch-event01-1.sv5:~$ clickhouse-backup download 2021_02_20_04_00_ch-event01.event_alert_local
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:06 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:06 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:06 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:07 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:07 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:08 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:08 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:08 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:09 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:09 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:09 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:10 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:10 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:11 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:11 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:11 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:12 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:12 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:12 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:13 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:13 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:14 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:14 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:14 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:15 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:15 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:16 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:16 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%2021/02/22 12:05:16 Backup '2021_02_20_04_00_ch-event01.event_alert_local' required '2021_02_20_04_00_ch-event01.event_alert_local'. Downloading.
 1.98 MiB / 1.98 MiB [====================================================================================================================================================================================================================================================================================================================] 100.00%^C


```

The restore gets stuck in an endless loop.

Maybe this isn't a valid use case, but either way clickhouse-backup (v0.6.4) should not loop like this. At a minimum it should report an error and exit.

My preferred behaviour is that it would just download the parts it can (reporting that the chain of backups is broken). This would mean that I can keep doing partial backups, no need for full backup at any point. I can then roll the older backups away on s3 when needed.


Discussion:

Patch:
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
deleted file mode 100644
--- a/.github/workflows/go.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-name: Go
-
-on:
-  push:
-    branches:
-      - '*'
-  # pull_request:
-  #   branches: [ master ]
-
-jobs:
-  build:
-    name: Build
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        clickhouse:
-          - '1.1.54390'
-          - '19.4.4.33'
-          - '19.15.3.6'
-          - '20.1.3.7'
-          - '20.6.3.28'
-    steps:
-      - uses: actions/checkout@v2
-      - uses: actions/setup-go@v2
-        with:
-          go-version: '^1.14'
-      - run: make build
-      - run: make config
-      - run: make test
-      - name: Integration test
-        env:
-          CLICKHOUSE_VERSION: ${{ matrix.clickhouse }}
-        run: echo "CLICKHOUSE_VERSION=${CLICKHOUSE_VERSION}"
-
diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml
new file mode 100644
--- /dev/null
+++ b/.github/workflows/pull_request.yaml
@@ -0,0 +1,85 @@
+name: Pull request handler
+
+on:
+  pull_request:
+    branches:
+      - master
+      - dev
+
+jobs:
+  pull_request:
+    name: Build
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        clickhouse:
+          - '1.1.54390'
+          - '19.11.12.69'
+          - '19.16.19.85'
+          - '20.3'
+          - '20.8'
+          - '21.2'
+    steps:
+      - name: Checkout project
+        uses: actions/checkout@v2
+
+      # be carefull with encrypt with old OpenSSL - https://habr.com/ru/post/535140/
+      - name: Decrypting credentials for Google Cloud Storage
+        env:
+          VAULT_PASSWORD: ${{ secrets.VAULT_PASSWORD }}
+        run: |
+          openssl version
+          openssl enc -base64 -aes-256-cbc -d -in test/integration/credentials.json.enc -out test/integration/credentials.json -md md5 -k ${VAULT_PASSWORD}
+
+      - name: Setup golang
+        id: setup-go
+        uses: actions/setup-go@v2
+        with:
+          go-version: '^1.14'
+
+
+      - name: Cache golang
+        id: cache-golang
+        uses: actions/cache@v2
+        with:
+          path: /github/home/go/pkg/mod
+          key: ${{ runner.os }}-${{ matrix.golang-version }}-golang-${{ hashFiles('go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-${{ matrix.golang-version }}-golang-
+
+      - name: Install golang dependencies
+        run: go mod download -x
+        if: |
+          steps.cache-golang.outputs.cache-hit != 'true'
+
+      - name: Setup docker-compose
+        run: |
+          apt-get update
+          apt-get install --no-install-recommends -y make python3-pip
+          python3 -m pip install -U pip
+          pip3 install --prefer-binary -U setuptools
+          pip3 install --prefer-binary -U docker-compose
+
+      - run: make build
+      - run: make config
+      - run: make test
+
+
+      - name: Running integration tests
+        env:
+          CLICKHOUSE_VERSION: ${{ matrix.clickhouse }}
+          GCS_TESTS: true
+          CGO_ENABLED: 0
+        run: |
+          set -x
+          echo "CLICKHOUSE_VERSION=${CLICKHOUSE_VERSION}"
+          if [[ "${CLICKHOUSE_VERSION}" == 2* ]]; then
+            export COMPOSE_FILE=docker-compose_storage-policy.yml
+          else
+            export COMPOSE_FILE=docker-compose.yml
+          fi
+          export CLICKHOUSE_BACKUP_BIN="$(pwd)/clickhouse-backup/clickhouse-backup"
+          docker-compose -f test/integration/${COMPOSE_FILE} up -d --force-recreate
+          docker-compose -f test/integration/${COMPOSE_FILE} ps -a
+          go test -tags=integration -v test/integration/integration_test.go
+
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,137 @@
+name: Build
+
+on:
+  push:
+    tags:
+      - v*.*.*
+
+jobs:
+  release:
+    name: Release
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout project
+        uses: actions/checkout@v2
+
+      - name: Setup golang
+        id: setup-go
+        uses: actions/setup-go@v2
+        with:
+          go-version: '^1.14'
+
+      - name: Setup fpm and make
+        run: |
+          sudo apt-get update
+          sudo apt-get install -y --no-install-recommends ruby ruby-dev gcc g++ rpm
+          sudo apt-get install --no-install-recommends -y make
+          sudo gem install --no-document fpm
+
+      - name: Cache golang
+        id: cache-golang
+        uses: actions/cache@v2
+        with:
+          path: /github/home/go/pkg/mod
+          key: ${{ runner.os }}-${{ matrix.golang-version }}-golang-${{ hashFiles('go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-${{ matrix.golang-version }}-golang-
+
+      - name: Install golang dependencies
+        run: go mod download -x
+        if: |
+          steps.cache-golang.outputs.cache-hit != 'true'
+
+      - name: Extract DOCKER_TAG version
+        id: docker_tag
+        run: |
+          DOCKER_TAG=${GITHUB_REF##*/}
+          DOCKER_TAG=${DOCKER_TAG##*\\}
+          export DOCKER_TAG=${DOCKER_TAG//v}
+          echo "::set-output name=docker_tag::${DOCKER_TAG:-dev}"
+
+
+      - run: make build
+      - run: make config
+      - run: make test
+
+      - name: Building deb, rpm and tar.gz packages
+        id: make_packages
+        run: |
+          export NAME=clickhouse-backup
+          export VERSION=$(git describe --always --tags --abbrev=0 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/c\1/;s/-/./g')
+          tar -czvf ${NAME}.tar.gz ${NAME}
+          CGO_ENABLED=0 make packages
+          echo "::set-output name=rpm::${NAME}-${VERSION}-1.x86_64.rpm"
+          echo "::set-output name=deb::${NAME}_${VERSION}_amd64.deb"
+          echo "::set-output name=tgz::${NAME}.tar.gz"
+
+      - name: Prepare release notes
+        id: release_notes
+        run: |
+          awk '/^# / {s++} s == 1 {print}' ChangeLog.md > /tmp/release_notes.md
+          echo "::set-output name=path::/tmp/release_notes.md"
+
+      - name: Create release
+        id: create_release
+        uses: actions/create-release@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          tag_name: ${{ steps.docker_tag.outputs.docker_tag }}
+          release_name: ${{ steps.docker_tag.outputs.docker_tag }}
+          body_path: ${{ steps.release_notes.outputs.path }}
+          draft: true
+
+      - name: Add rpm to github release
+        id: upload-release-rpm
+        uses: actions/upload-release-asset@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          upload_url: ${{ steps.create_release.outputs.upload_url }}
+          asset_path: build/${{ steps.make_packages.outputs.rpm }}
+          asset_name: ${{ steps.make_packages.outputs.rpm }}
+          asset_content_type: application/octet-stream
+
+
+      - name: Add deb to github release
+        id: upload-release-deb
+        uses: actions/upload-release-asset@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          upload_url: ${{ steps.create_release.outputs.upload_url }}
+          asset_path: build/${{ steps.make_packages.outputs.deb }}
+          asset_name: ${{ steps.make_packages.outputs.deb }}
+          asset_content_type: application/octet-stream
+
+      - name: Add tar.gz to github release
+        id: upload-release-tgz
+        uses: actions/upload-release-asset@v1
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        with:
+          upload_url: ${{ steps.create_release.outputs.upload_url }}
+          asset_path: ${{ steps.make_packages.outputs.tgz }}
+          asset_name: ${{ steps.make_packages.outputs.tgz }}
+          asset_content_type: application/octet-stream
+
+      - name: Building docker image
+        env:
+          DOCKER_REPO: ${{ secrets.DOCKER_REPO }}
+          DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }}
+          DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
+          DOCKER_USER: ${{ secrets.DOCKER_USER }}
+          DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
+          DOCKER_TAG: ${{ steps.docker_tag.outputs.docker_tag }}
+        run: |
+          echo ${DOCKER_BRANCH} ${DOCKER_TAG} ${DOCKER_REPO}
+          echo ${DOCKER_TOKEN} | docker login -u ${DOCKER_USER} --password-stdin
+
+          docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
+          docker image tag ${DOCKER_IMAGE}:${DOCKER_TAG} $DOCKER_REGISTRY/${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG}
+          docker image tag ${DOCKER_IMAGE}:${DOCKER_TAG} $DOCKER_REGISTRY/${DOCKER_REPO}/${DOCKER_IMAGE}:latest
+          docker push ${DOCKER_REGISTRY}/${DOCKER_REPO}/${DOCKER_IMAGE}:${DOCKER_TAG}
+          docker push ${DOCKER_REGISTRY}/${DOCKER_REPO}/${DOCKER_IMAGE}:latest
+
+
+
diff --git a/ChangeLog.md b/ChangeLog.md
new file mode 100644
--- /dev/null
+++ b/ChangeLog.md
@@ -0,0 +1,19 @@
+# v0.6.5
+
+IMPROVEMENTS
+
+- add Atomic Database Engine support
+- add Multi Volumes support
+- improve prometheus metrics
+
+# v0.6.4
+
+IMPROVEMENTS
+
+- Added CLICKHOUSE_AUTO_CLEAN_SHADOW option for cleaning shadow folder before backup. Enabled by default.
+- Added CLICKHOUSE_SYNC_REPLICATED_TABLES option for sync replicated tables before backup. Enabled by default.
+- Improved statuses of operations in server mode
+
+BUG FIXES
+
+- Fixed bug with semaphores in server mode
diff --git a/Dockerfile b/Dockerfile
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,13 +1,18 @@
 #FROM scratch
-FROM alpine
+FROM alpine:3.12
 
-#RUN adduser -D -g '' clickhouse
-RUN apk update && apk add --no-cache ca-certificates tzdata && update-ca-certificates
+RUN addgroup -S -g 101 clickhouse \
+    && adduser -S -h /var/lib/clickhouse -s /bin/bash -G clickhouse -g "ClickHouse server" -u 101 clickhouse \
+    && mkdir -p /var/lib/clickhouse/backup /etc/clickhouse-backup \
+    && chown -R clickhouse:clickhouse /var/lib/clickhouse \
+    && chmod ugo+Xrw -R /var/lib/clickhouse /etc/clickhouse-backup
+
+RUN apk update && apk add --no-cache su-exec ca-certificates tzdata bash && update-ca-certificates
 
 COPY clickhouse-backup/clickhouse-backup /bin/clickhouse-backup
 RUN chmod +x /bin/clickhouse-backup
 
-#USER clickhouse
+USER clickhouse
 
-ENTRYPOINT [ "/bin/clickhouse-backup" ]
-CMD [ "--help" ]
+ENTRYPOINT [ "/bin/bash" ]
+CMD [ "-c", "/bin/clickhouse-backup --help" ]
diff --git a/config/config.go b/config/config.go
--- a/config/config.go
+++ b/config/config.go
@@ -153,7 +153,7 @@ func (cfg *Config) GetArchiveExtension() string {
 	}
 }
 
- func (cfg *Config) GetCompressionFormat() string {
+func (cfg *Config) GetCompressionFormat() string {
 	switch cfg.General.RemoteStorage {
 	case "s3":
 		return cfg.S3.CompressionFormat
@@ -170,7 +170,7 @@ func (cfg *Config) GetArchiveExtension() string {
 	default:
 		return "unknown"
 	}
- }
+}
 
 // LoadConfig - load config from file
 func LoadConfig(configLocation string) (*Config, error) {
diff --git a/pkg/backup/print.go b/pkg/backup/print.go
--- a/pkg/backup/print.go
+++ b/pkg/backup/print.go
@@ -35,7 +35,7 @@ func printBackups(w io.Writer, backupList []new_storage.Backup, format, location
 		// 	fmt.Println("no backups found")
 		// }
 		for _, backup := range backupList {
-			size := utils.FormatBytes(backup.DataSize+backup.MetadataSize)
+			size := utils.FormatBytes(backup.DataSize + backup.MetadataSize)
 			backupFormat := backup.DataFormat
 			if backup.Legacy {
 				if location == "local" {
diff --git a/pkg/metadata/metadata.go b/pkg/metadata/metadata.go
--- a/pkg/metadata/metadata.go
+++ b/pkg/metadata/metadata.go
@@ -33,9 +33,9 @@ type TableMetadata struct {
 	// Macros ???
 	Size                 map[string]int64 `json:"size"`                  // сколько занимает бэкап на каждом диске
 	TotalBytes           int64            `json:"total_bytes,omitempty"` // общий объём бэкапа
-	DependencesTable     string `json:"dependencies_table,omitempty"`
-	DependenciesDatabase string `json:"dependencies_database,omitempty"`
-	MetadataOnly         bool   `json:"metadata_only"`
+	DependencesTable     string           `json:"dependencies_table,omitempty"`
+	DependenciesDatabase string           `json:"dependencies_database,omitempty"`
+	MetadataOnly         bool             `json:"metadata_only"`
 }
 
 type Part struct {
diff --git a/pkg/new_storage/azblob.go b/pkg/new_storage/azblob.go
--- a/pkg/new_storage/azblob.go
+++ b/pkg/new_storage/azblob.go
@@ -130,7 +130,7 @@ func (s *AzureBlob) Walk(azPath string, recursive bool, process func(r RemoteFil
 	ctx := context.Background()
 	prefix := path.Join(s.Config.Path, azPath)
 	opt := azblob.ListBlobsSegmentOptions{
-		Prefix:  prefix + "/",
+		Prefix: prefix + "/",
 	}
 	mrk := azblob.Marker{}
 	delimiter := ""
@@ -145,7 +145,7 @@ func (s *AzureBlob) Walk(azPath string, recursive bool, process func(r RemoteFil
 		}
 		for _, p := range r.Segment.BlobPrefixes {
 			process(&azureBlobFile{
-				name:         strings.TrimPrefix(p.Name, prefix),
+				name: strings.TrimPrefix(p.Name, prefix),
 			})
 		}
 		for _, blob := range r.Segment.BlobItems {
diff --git a/pkg/new_storage/cos.go b/pkg/new_storage/cos.go
--- a/pkg/new_storage/cos.go
+++ b/pkg/new_storage/cos.go
@@ -86,7 +86,7 @@ func (c *COS) Walk(cosPath string, recursuve bool, process func(RemoteFile) erro
 	}
 	res, _, err := c.client.Bucket.Get(context.Background(), &cos.BucketGetOptions{
 		Delimiter: delimiter,
-		Prefix: prefix,
+		Prefix:    prefix,
 	})
 	if err != nil {
 		return err
diff --git a/pkg/new_storage/gcs.go b/pkg/new_storage/gcs.go
--- a/pkg/new_storage/gcs.go
+++ b/pkg/new_storage/gcs.go
@@ -100,7 +100,7 @@ func (gcs *GCS) PutFile(key string, r io.ReadCloser) error {
 	obj := gcs.client.Bucket(gcs.Config.Bucket).Object(path.Join(gcs.Config.Path, key))
 	writer := obj.NewWriter(ctx)
 	defer writer.Close()
-	_, err :=  io.CopyBuffer(writer, r, gcs.buffer)
+	_, err := io.CopyBuffer(writer, r, gcs.buffer)
 	return err
 }
 


Test patch:
diff --git a/test/integration/docker-compose.yml b/test/integration/docker-compose.yml
--- a/test/integration/docker-compose.yml
+++ b/test/integration/docker-compose.yml
@@ -14,7 +14,7 @@ services:
       - clickhouse-backup
 
   clickhouse:
-    image: yandex/clickhouse-server:${CLICKHOUSE_VERSION:-20.10.3.30}
+    image: yandex/clickhouse-server:${CLICKHOUSE_VERSION:-20.10.7.4}
     container_name: clickhouse
     environment:
       TZ: UTC