Last active
December 16, 2015 12:49
-
-
Save jweslley/5437568 to your computer and use it in GitHub Desktop.
Backup script to Gitlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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