Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EarthShaping/5a3ab45d6f90238dd6ef5121080e444b to your computer and use it in GitHub Desktop.
Save EarthShaping/5a3ab45d6f90238dd6ef5121080e444b to your computer and use it in GitHub Desktop.
RepositoryHosting.com backup download script
#!/bin/sh
# RepositoryHosting.com backup download script
#
# This script downloads your daily RepositoryHosting.com backups.
##################################################################
##
### Configuration
##
# Subdomain of your repository
RepoSubdomain=mysubdomain
# Local backup directory
BackupDir=~/Backups/RepositoryHosting.com
# RepositoryHosting.com administrator credentials
Username=myadminusername
Password=mypassword
# List of project names (for naming the backups, the order of these
# equate to the project IDs in your RepositoryHosting.com account.)
ProjectNames=(
MyProject
CoolProject
OtherProject
)
# Backup date formats (e.g. "+%Y%m%d" for YYYYMMDD, or "+%d" for DD)
# NOTE: This affects the number of backups that will be kept, e.g.
# "+%d" will store a month's worth of backups, each numbered as the
# day of the month when it was created, "+%Y%m%d will keep an infinite
# number of backups, as each one will be uniquely dated.
#
# NOTE: This is used only if you specify @@Date in the filename format.
#
FileDateFormat="+%d"
# Subdirectory date format (same as above, used only if you specify
# @@Date in your SubDirFormat).
#
#SubDirDateFormat="+%m"
# Backup subdirectory format. If specified will place your backups into
# a separate subdirectory for each project.
#
SubDirFormat="@@ProjectName"
# Backup file name format (e.g. "@@ProjectName.@@Date").
# This will automatically be prepended with the $BackupDir/$SubDir/ and
# appended with ".tar.gz".
#
FileNameFormat="@@ProjectName.@@Date"
##
### End configuration (no need to edit past here)
##
##################################################################
# Resolve URLs
RepoBaseUrl="https://$RepoSubdomain.repositoryhosting.com"
SessionStartUrl="$RepoBaseUrl/session"
ProjectsBaseUrl="$RepoBaseUrl/projects"
# Messages
echo -e "\nDownloading today's backups \n\tFrom:\t$RepoBaseUrl"\
"\n\tTo:\t$BackupDir"
# Cookie file name
CookieFileName="cookies.txt"
# Create backup directory if it doesn't exist
mkdir -p "$BackupDir"
# Go to backup directory
cd "$BackupDir"
# Login
echo -e "\nLogging in..."
curl -sS -X POST $SessionStartUrl -d \
"username=$Username&password=$Password" -c $CookieFileName -o /dev/null
# Copy project backups
ProjectNumber=0
while [ "x${ProjectNames[ProjectNumber]}" != "x" ]
do
# Specify & create backup subdirectory for this project
ProjectBackupSubdir=\
"${SubDirFormat//@@ProjectName/${ProjectNames[ProjectNumber]}}"
ProjectBackupSubdir=\
"${ProjectBackupSubdir//@@Date/`date $SubDirDateFormat`}"
test "x$ProjectBackupSubdir" != "x" && mkdir -p $ProjectBackupSubdir && \
ProjectBackupSubdir="$ProjectBackupSubdir/"
# Resolve backup filename
ProjectBackupFile=\
"${FileNameFormat//@@ProjectName/${ProjectNames[ProjectNumber]}}"
ProjectBackupFile=\
"${ProjectBackupFile//@@Date/`date $FileDateFormat`}.tar.gz"
# Copy project backup
echo -e "\nCopying ${ProjectNames[ProjectNumber]} backup to "\
"\n\t$ProjectBackupSubdir$ProjectBackupFile"
curl -L "$ProjectsBaseUrl/$[ProjectNumber+1]/backups/`date +%Y/%m/%d/00`" \
-b $CookieFileName -# \
-o "$BackupDir/$ProjectBackupSubdir$ProjectBackupFile"
ProjectNumber=$[$ProjectNumber+1]
done
# Delete cookies.txt
rm $CookieFileName
echo -e "\nFinished downloading backups!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment