Commit 64a16570 authored by Kirill Smelkov's avatar Kirill Smelkov

gitlab-backup: Use find in a way, that does not hide errors

In 495bd2fa (gitlab-backup: Unpack *.tar.gz before storing them in git)
we used find(1) to find *.tar.gz and unpack/repack them on
backup/restore. However `find -exec ...` does not stop on errors and
does not report them. Compare:

    ---- 8< ---- x.sh
    #!/bin/bash -e

    echo AAA
    find . -exec false ';'
    echo BBB
    ---- 8< ----

    ---- 8< ---- y.sh
    #!/bin/bash -e

    echo XXX
    find . | \
    while read F; do
        false
    done
    echo YYY
    ---- 8< ----

    $ ./x.sh
    AAA
    BBB
    $ echo $?
    0

    $ ./y.sh
    XXX
    $ echo $?
    1

So we switch to second style where find passes entries to processing
program via channel. This second new style is also more clean, in my view,
because listing and processing parts are now more better structured.

/cc @kazuhiko
parent 70776a8f
......@@ -56,10 +56,16 @@ backup_pull() {
tar -C "$tmpd/gitlab_backup" -xf "$backup_tar"
gzip -d "$tmpd/gitlab_backup/db/database.sql.gz" # unzip so it is better stored in git
# unpack tarballs so files are better stored in git
find "$tmpd/gitlab_backup" -maxdepth 1 -type f -name "*.tar.gz" -exec \
sh -c 'mv {} {}.x && mkdir {} && tar xf {}.x -C {} && rm {}.x' ';'
find "$tmpd/gitlab_backup" -maxdepth 1 -type d -name "*.tar.gz" -empty -exec \
touch {}/.gitlab-backup-keep ';'
find "$tmpd/gitlab_backup" -maxdepth 1 -type f -name "*.tar.gz" | \
while read tar; do
mv $tar $tar.x
mkdir $tar
tar xf $tar.x -C $tar
rm $tar.x
# keep empty dirs too
test -n "`ls -A $tar`" || touch $tar/.gitlab-backup-keep
done
# 3. pull gitlab data into git-backup
......@@ -88,10 +94,14 @@ backup_restore() {
$GIT_BACKUP restore $HEAD gitlab/misc:"$tmpd/gitlab_backup"
gzip "$tmpd/gitlab_backup/db/database.sql" # gzip sql dump, as gitlab expects .gz
# recreate tarballs from *.tar.gz directories
find "$tmpd/gitlab_backup" -maxdepth 1 -type d -name "*.tar.gz" -exec \
rm -f {}/.gitlab-backup-keep ';'
find "$tmpd/gitlab_backup" -maxdepth 1 -type d -name "*.tar.gz" -exec \
sh -c 'mv {} {}.x && tar cfz {} -C {}.x . && rm -rf {}.x' ';'
find "$tmpd/gitlab_backup" -maxdepth 1 -type d -name "*.tar.gz" | \
while read tar; do
rm -f $tar/.gitlab-backup-keep
mv $tar $tar.x
tar cfz $tar -C $tar.x .
rm -rf $tar.x
done
# 2. find out backup timestamp as saved by gitlab
backup_created_at=`grep :backup_created_at: "$tmpd/gitlab_backup/backup_information.yml" |
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment