Skip to content

Instantly share code, notes, and snippets.

@NicolasCARPi
Created February 11, 2016 03:36
Show Gist options
  • Save NicolasCARPi/5d9e2599857a148a54b0 to your computer and use it in GitHub Desktop.
Save NicolasCARPi/5d9e2599857a148a54b0 to your computer and use it in GitHub Desktop.
Backup an elabftw installation
#!/bin/sh
# backup.sh - Backup eLabFTW installation
# ------
# CONFIG
# ------
BACKUP_DIR='~/.backups/elabftw'
ELAB_ROOT='/var/www/html/elabftw'
DB_HOST='localhost'
DB_NAME='elabftw'
DB_USER='elabftw'
DB_PASSWORD='secr3t'
# ----------
# END CONFIG
# ----------
# create the dir if it's not here already
mkdir -p ${BACKUP_DIR}
# get clean date
date=$(date --iso-8601) # 2016-02-10
# elab sql backup
#################
# make a dump of the database in elabftw.sql file
mysqldump -h${DB_HOST} -u${DB_USER} -p${DB_PASSWORD} -r dump.sql ${DB_NAME}
# compress the file
gzip dump.sql
# copy this file somewhere else using ssh (scp)
# this requires to have ssh correctly configured with public key authentication
#scp -q ${DB_NAME}.sql.gz user@computer:.backups/elabftw-${date}.sql.gz
# move the file to a local backup dir
mv dump.sql.gz ${BACKUP_DIR}/elabftw-${date}.sql.gz
# uploaded files backup
#######################
# make a zip of the uploads folder
zip -rq archive.zip ${ELAB_ROOT}/uploads
# add the config file
zip -rq archive.zip ${ELAB_ROOT}/config.php
# copy the tarball to somewhere else using ssh (scp)
#scp -q archive.zip user@computer:.backups/elabftw-${date}.zip
# move the file to a local backup dir
mv archive.zip ${BACKUP_DIR}/elabftw-${date}.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment