Skip to content

Instantly share code, notes, and snippets.

@artzub
Last active June 4, 2023 15:02
Show Gist options
  • Save artzub/1feaac7e1d2ccee220fb to your computer and use it in GitHub Desktop.
Save artzub/1feaac7e1d2ccee220fb to your computer and use it in GitHub Desktop.
gitlab backupt to yadisk
#!/bin/bash
#####
# install yadisk
#
# $ echo "deb http://repo.yandex.ru/yandex-disk/deb/ stable main" | tee -a /etc/apt/sources.list.d/yandex.list > /dev/null && wget http://repo.yandex.ru/yandex-disk/YANDEX-DISK-KEY.GPG -O- | apt-key add - && apt-get update && apt-get install -y yandex-disk
#
# $ yandex-disk setup
#
# add cron command
#
# $ crontab -e
# append
# 0 7 * * */3 /root/backup_gitlab.sh
#####
###
# docs
#
# https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/raketasks/backup_restore.md
###
yandex-disk start
#--exclude-dirs="db_backups,upload_backups"
backups="/var/opt/gitlab/backups"
root_dir="backups_repos"
year=`date +%Y`
month=`date +%m`
key=`date +%w`
echo "backup gitlab"
[ -d /mnt/yadrive/$root_dir/ ] || mkdir /mnt/yadrive/$root_dir/
full=/mnt/yadrive/$root_dir/$key
[ -d $full ] || mkdir $full
gitlab-rake gitlab:backup:create
cp -avr $backups $full
echo "sync with yandex"
i=0
while true; do
yap=`yandex-disk status | grep "Sync progress:" | sed 's/ //g'`
yas=`yandex-disk status | grep "Synchronization core status:" | cut -d':' -f2 | sed 's/ //g'`
echo "status: $yas | $yap";
if [ $i -gt 1800 ]; then
break;
fi
let i++
if [ "$yas" != "idle" ]; then
sleep 1
else
break;
fi
done
yandex-disk stop
sleep 60
killall -s9 yandex-disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment