Skip to content

Instantly share code, notes, and snippets.

@jweslley
Last active December 16, 2015 12:49
Show Gist options
  • Save jweslley/5437568 to your computer and use it in GitHub Desktop.
Save jweslley/5437568 to your computer and use it in GitHub Desktop.
Backup script to Gitlab
#!/bin/sh
# Usage:
# - Save this file in /etc/cron.daily/gitlab
# - Enable execution permission: chmod +x /etc/cron.daily/gitlab
set -e
DB_USERNAME=username
DB_PASSWORD=secret
BACKUP_DIR='/path/to/backup/'
TIMESTAMP=`date +'%Y%m%d%H%M%S'`
# Mysql database
mysqldump --user=$DB_USERNAME --password='$DB_PASSWORD' gitlabhq_production | gzip > "$BACKUP_DIR/$TIMESTAMP-mysql.sql.gz"
# Uploads
tar zcf "$BACKUP_DIR/$TIMESTAMP-uploads.tar.gz" \
--directory /home/git/gitlab/public/ \
uploads
# Git repositories
tar zcf "$BACKUP_DIR/$TIMESTAMP-repositories.tar.gz" \
--directory /home/git/ \
repositories
# Remove backup files older than 5 days
find $BACKUP_DIR -mtime +5 -type f -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment