create automatic backups job only if it does not already exist

This commit is contained in:
Sameer Naik 2015-12-19 23:37:22 +05:30
parent 6c921ffd4a
commit 8fd099d45f

View File

@ -549,21 +549,21 @@ gitlab_configure_sidekiq() {
gitlab_configure_backups_cron() {
case ${GITLAB_BACKUP_SCHEDULE} in
daily|weekly|monthly)
echo "Configuring gitlab::backups::cron..."
read hour min <<< ${GITLAB_BACKUP_TIME//[:]/ }
day_of_month=*
month=*
day_of_week=*
case ${GITLAB_BACKUP_SCHEDULE} in
daily) ;;
weekly) day_of_week=0 ;;
monthly) day_of_month=01 ;;
esac
exec_as_git cat >> /tmp/cron.${GITLAB_USER} <<EOF
# Automatic Backups ($GITLAB_BACKUP_SCHEDULE)
$min $hour $day_of_month $month $day_of_week /bin/bash -l -c 'cd ${GITLAB_INSTALL_DIR} && bundle exec rake gitlab:backup:create RAILS_ENV=${RAILS_ENV}'
EOF
crontab -u ${GITLAB_USER} /tmp/cron.${GITLAB_USER}
if [[ ! $(crontab -u ${GITLAB_USER} -l >/tmp/cron.${GITLAB_USER} 2>/dev/null) || \
! $(grep -q 'bundle exec rake gitlab:backup:create' /tmp/cron.${GITLAB_USER}) ]]; then
echo "Configuring gitlab::backups::cron..."
read hour min <<< ${GITLAB_BACKUP_TIME//[:]/ }
day_of_month=*
month=*
day_of_week=*
case ${GITLAB_BACKUP_SCHEDULE} in
daily) ;;
weekly) day_of_week=0 ;;
monthly) day_of_month=01 ;;
esac
echo "$min $hour $day_of_month $month $day_of_week /bin/bash -l -c 'cd ${GITLAB_INSTALL_DIR} && bundle exec rake gitlab:backup:create RAILS_ENV=${RAILS_ENV}'" >> /tmp/cron.${GITLAB_USER}
crontab -u ${GITLAB_USER} /tmp/cron.${GITLAB_USER}
fi
rm -rf /tmp/cron.${GITLAB_USER}
;;
esac