Skip to content

Instantly share code, notes, and snippets.

@wienczny
Last active January 11, 2020 22:53
Show Gist options
  • Save wienczny/6a3bc449cbb33234b59f to your computer and use it in GitHub Desktop.
Save wienczny/6a3bc449cbb33234b59f to your computer and use it in GitHub Desktop.
Phabricator Backup, Update and Launch script.
#!/bin/sh
set -e
set -x
# This script should be run as user phabricator
# This is an example script for updating Phabricator, similar to the one used to
# update <https://secure.phabricator.com/>. It might not work perfectly on your
# system, but hopefully it should be easy to adapt. This script is not intended
# to work without modifications.
# NOTE: This script assumes you are running it from a directory which contains
# arcanist/, libphutil/, and phabricator/.
SCRIPT=$(readlink -f "$0")
ROOT="/srv/http" # You can hard-code the path here instead.
DATA="/srv/phabricator"
BACKUP="/srv/backup" # Backup directory
REPOSITORY="/srv/backup/phabricator.borg"
cd $ROOT
PHABRICATOR_UID=`stat -c %u $ROOT/phabricator`
CURRENT_UID=`id -u`
### STOP WEB SERVER AND DAEMONS ###############################################
# Stop daemons.
sudo /bin/systemctl stop phabricator-phd
# If running the notification server, stop it.
sudo /bin/systemctl stop phabricator-aphlict
# Stop the webserver (apache, nginx, lighttpd, etc). This command will differ
# depending on which system and webserver you are running: replace it with an
# appropriate command for your system.
# NOTE: If you're running php-fpm, you should stop it here too.
sudo /bin/systemctl stop nginx
sudo /bin/systemctl stop php5-fpm
### CHANGE USER ################################################################
if [ "$CURRENT_UID" != "$PHABRICATOR_UID" ]; then
sudo -u "#$PHABRICATOR_UID" "$SCRIPT"
exit 0
fi
### BACKUP #####################################################################
mkdir -p "${DATA}/backup"
"$ROOT/phabricator/bin/storage" dump > "${DATA}/backup/phabricator-mysql.sql"
borg create --verbose --progress --stats --exclude-caches --one-file-system --compression=lzma,9 \
"$REPOSITORY::phabricator-`date --iso-8601=seconds`"\
"${ROOT}" \
"${DATA}"
### UPDATE WORKING COPIES ######################################################
echo "Update libphutil"
cd "$ROOT/libphutil"
git pull
echo "Update arcanist"
cd "$ROOT/arcanist"
git pull
echo "Update phabricator"
cd "$ROOT/phabricator"
git pull
### START WEB SERVER AND DAEMONS ###############################################
# Upgrade the database schema. You may want to add the "--force" flag to allow
# this script to run noninteractively.
"$ROOT/phabricator/bin/storage" upgrade --force
# Restart the webserver. As above, this depends on your system and webserver.
# NOTE: If you're running php-fpm, restart it here too.
sudo /bin/systemctl start php5-fpm
sudo /bin/systemctl start nginx
# Restart daemons.
sudo /bin/systemctl start phabricator-phd
# If running the notification server, start it.
sudo /bin/systemctl start phabricator-aphlict
### CLEAN OLD BACKUPS ########################################################
borg prune -v "$REPOSITORY" --keep-daily=7 --keep-weekly=4 --keep-monthly=6
@wienczny
Copy link
Author

Updated from attic to borg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment