Skip to content

Instantly share code, notes, and snippets.

@wienczny
Last active January 11, 2020 22:53

Revisions

  1. wienczny revised this gist Mar 30, 2016. 1 changed file with 24 additions and 21 deletions.
    45 changes: 24 additions & 21 deletions update_phabricator.sh
    Original file line number Diff line number Diff line change
    @@ -17,22 +17,22 @@ 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.attic"
    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
    # 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.

    @@ -48,29 +48,32 @@ fi

    ### BACKUP #####################################################################

    mkdir -p ${DATA}/backup
    $ROOT/phabricator/bin/storage dump > ${DATA}/backup/phabricator-mysql.sql
    attic create --stats \
    $REPOSITORY::phabricator-`date --iso-8601=seconds` \
    ${ROOT} \
    ${DATA}
    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 ######################################################

    cd $ROOT/libphutil
    echo "Update libphutil"
    cd "$ROOT/libphutil"
    git pull

    cd $ROOT/arcanist
    echo "Update arcanist"
    cd "$ROOT/arcanist"
    git pull

    cd $ROOT/phabricator
    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
    "$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.
    @@ -85,4 +88,4 @@ sudo /bin/systemctl start phabricator-aphlict

    ### CLEAN OLD BACKUPS ########################################################

    attic prune -v $REPOSITORY --keep-daily=7 --keep-weekly=4 --keep-monthly=6
    borg prune -v "$REPOSITORY" --keep-daily=7 --keep-weekly=4 --keep-monthly=6
  2. wienczny revised this gist Nov 27, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions update_phabricator.sh
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ set -x
    # 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
    @@ -41,7 +42,7 @@ sudo /bin/systemctl stop php5-fpm
    ### CHANGE USER ################################################################

    if [ "$CURRENT_UID" != "$PHABRICATOR_UID" ]; then
    sudo -u "#$PHABRICATOR_UID" "./$0"
    sudo -u "#$PHABRICATOR_UID" "$SCRIPT"
    exit 0
    fi

    @@ -50,7 +51,7 @@ fi
    mkdir -p ${DATA}/backup
    $ROOT/phabricator/bin/storage dump > ${DATA}/backup/phabricator-mysql.sql
    attic create --stats \
    $REPOSITORY::phabricator-`date +%Y-%m-%d-%H-%M` \
    $REPOSITORY::phabricator-`date --iso-8601=seconds` \
    ${ROOT} \
    ${DATA}

  3. wienczny revised this gist Nov 17, 2015. 1 changed file with 19 additions and 19 deletions.
    38 changes: 19 additions & 19 deletions update_phabricator.sh
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,7 @@
    set -e
    set -x

    # This script should be run as user phabricator. If not run as phabricator it
    # tries to sudo into this script again as phabricator.
    # 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
    @@ -15,7 +14,9 @@ set -x
    # arcanist/, libphutil/, and phabricator/.

    ROOT="/srv/http" # You can hard-code the path here instead.
    DATA="/srv/phabricator"
    BACKUP="/srv/backup" # Backup directory
    REPOSITORY="/srv/backup/phabricator.attic"

    cd $ROOT
    PHABRICATOR_UID=`stat -c %u $ROOT/phabricator`
    @@ -24,17 +25,18 @@ CURRENT_UID=`id -u`
    ### STOP WEB SERVER AND DAEMONS ###############################################

    # Stop daemons.
    $ROOT/phabricator/bin/phd stop
    sudo /bin/systemctl stop phabricator-phd

    # If running the notification server, stop it.
    $ROOT/phabricator/bin/aphlict stop
    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 /etc/init.d/nginx stop
    sudo /etc/init.d/php5-fpm stop

    sudo /bin/systemctl stop nginx
    sudo /bin/systemctl stop php5-fpm

    ### CHANGE USER ################################################################

    @@ -45,12 +47,12 @@ fi

    ### BACKUP #####################################################################

    # datestamp has a formatted date
    DATESTAMP=`date +"%Y-%m-%d"`

    mkdir -p ${BACKUP}
    $ROOT/phabricator/bin/storage dump | xz > ${BACKUP}/phabricator-mysql-${DATESTAMP}.xz
    tar -cJf ${BACKUP}/phabricator-data-${DATESTAMP}.tar.xz ${ROOT}
    mkdir -p ${DATA}/backup
    $ROOT/phabricator/bin/storage dump > ${DATA}/backup/phabricator-mysql.sql
    attic create --stats \
    $REPOSITORY::phabricator-`date +%Y-%m-%d-%H-%M` \
    ${ROOT} \
    ${DATA}

    ### UPDATE WORKING COPIES ######################################################

    @@ -71,17 +73,15 @@ $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 /etc/init.d/php5-fpm start
    sudo /etc/init.d/nginx start
    sudo /bin/systemctl start php5-fpm
    sudo /bin/systemctl start nginx

    # Restart daemons.
    $ROOT/phabricator/bin/phd start
    sudo /bin/systemctl start phabricator-phd

    # If running the notification server, start it.
    $ROOT/phabricator/bin/aphlict start
    sudo /bin/systemctl start phabricator-aphlict

    ### CLEAN OLD BACKUPS ########################################################

    if [ -d ${BACKUP} ]; then
    find ${BACKUP} -mtime +15 -type f -exec rm -v {} \;
    fi
    attic prune -v $REPOSITORY --keep-daily=7 --keep-weekly=4 --keep-monthly=6
  4. wienczny revised this gist Sep 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion update_phabricator.sh
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ fi
    ### BACKUP #####################################################################

    # datestamp has a formatted date
    DATESTAMP=`date +"%d-%m-%Y"`
    DATESTAMP=`date +"%Y-%m-%d"`

    mkdir -p ${BACKUP}
    $ROOT/phabricator/bin/storage dump | xz > ${BACKUP}/phabricator-mysql-${DATESTAMP}.xz
  5. wienczny revised this gist Apr 6, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions update_phabricator.sh
    Original file line number Diff line number Diff line change
    @@ -49,8 +49,8 @@ fi
    DATESTAMP=`date +"%d-%m-%Y"`

    mkdir -p ${BACKUP}
    $ROOT/phabricator/bin/storage dump | gzip > ${BACKUP}/phabricator-mysql-${DATESTAMP}.gz
    tar -cjvf ${BACKUP}/phabricator-data-${DATESTAMP}.tar.bz2 ${ROOT}
    $ROOT/phabricator/bin/storage dump | xz > ${BACKUP}/phabricator-mysql-${DATESTAMP}.xz
    tar -cJf ${BACKUP}/phabricator-data-${DATESTAMP}.tar.xz ${ROOT}

    ### UPDATE WORKING COPIES ######################################################

    @@ -83,5 +83,5 @@ $ROOT/phabricator/bin/aphlict start
    ### CLEAN OLD BACKUPS ########################################################

    if [ -d ${BACKUP} ]; then
    find ${BACKUP} -mtime +7 -type f -exec rm -v {} \;
    find ${BACKUP} -mtime +15 -type f -exec rm -v {} \;
    fi
  6. wienczny renamed this gist Mar 10, 2015. 1 changed file with 37 additions and 18 deletions.
    55 changes: 37 additions & 18 deletions Phabricator Update + Launch → update_phabricator.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,8 @@
    set -e
    set -x

    # This script should be run as user phabricator. If run as root it switches user
    # This script should be run as user phabricator. If not run as phabricator it
    # tries to sudo into this script again as 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
    @@ -14,16 +15,43 @@ set -x
    # arcanist/, libphutil/, and phabricator/.

    ROOT="/srv/http" # You can hard-code the path here instead.
    BACKUP="/srv/backup" # Backup directory

    cd $ROOT
    PHABRICATOR_UID=`stat -c %u $ROOT/phabricator`
    CURRENT_UID=`id -u`

    ### STOP WEB SERVER AND DAEMONS ###############################################

    # Stop daemons.
    $ROOT/phabricator/bin/phd stop

    # If running the notification server, stop it.
    $ROOT/phabricator/bin/aphlict stop

    # 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 /etc/init.d/nginx stop
    sudo /etc/init.d/php5-fpm stop

    ### CHANGE USER ################################################################

    if [ "$CURRENT_UID" != "$PHABRICATOR_UID" ]; then
    sudo -u "#$PHABRICATOR_UID" "./$0"
    exit 0
    fi

    ### BACKUP #####################################################################

    # datestamp has a formatted date
    DATESTAMP=`date +"%d-%m-%Y"`

    mkdir -p ${BACKUP}
    $ROOT/phabricator/bin/storage dump | gzip > ${BACKUP}/phabricator-mysql-${DATESTAMP}.gz
    tar -cjvf ${BACKUP}/phabricator-data-${DATESTAMP}.tar.bz2 ${ROOT}

    ### UPDATE WORKING COPIES ######################################################

    cd $ROOT/libphutil
    @@ -35,22 +63,7 @@ git pull
    cd $ROOT/phabricator
    git pull


    ### CYCLE WEB SERVER AND DAEMONS ###############################################

    # Stop daemons.
    $ROOT/phabricator/bin/phd stop

    # If running the notification server, stop it.
    $ROOT/phabricator/bin/aphlict stop

    # 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 /etc/init.d/nginx stop
    sudo /etc/init.d/php5-fpm stop
    ### START WEB SERVER AND DAEMONS ###############################################

    # Upgrade the database schema. You may want to add the "--force" flag to allow
    # this script to run noninteractively.
    @@ -65,4 +78,10 @@ sudo /etc/init.d/nginx start
    $ROOT/phabricator/bin/phd start

    # If running the notification server, start it.
    sudo $ROOT/phabricator/bin/aphlict start
    $ROOT/phabricator/bin/aphlict start

    ### CLEAN OLD BACKUPS ########################################################

    if [ -d ${BACKUP} ]; then
    find ${BACKUP} -mtime +7 -type f -exec rm -v {} \;
    fi
  7. wienczny created this gist Oct 14, 2014.
    68 changes: 68 additions & 0 deletions Phabricator Update + Launch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #!/bin/sh

    set -e
    set -x

    # This script should be run as user phabricator. If run as root it switches user

    # 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/.

    ROOT="/srv/http" # You can hard-code the path here instead.

    cd $ROOT
    PHABRICATOR_UID=`stat -c %u $ROOT/phabricator`
    CURRENT_UID=`id -u`

    if [ "$CURRENT_UID" != "$PHABRICATOR_UID" ]; then
    sudo -u "#$PHABRICATOR_UID" "./$0"
    exit 0
    fi

    ### UPDATE WORKING COPIES ######################################################

    cd $ROOT/libphutil
    git pull

    cd $ROOT/arcanist
    git pull

    cd $ROOT/phabricator
    git pull


    ### CYCLE WEB SERVER AND DAEMONS ###############################################

    # Stop daemons.
    $ROOT/phabricator/bin/phd stop

    # If running the notification server, stop it.
    $ROOT/phabricator/bin/aphlict stop

    # 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 /etc/init.d/nginx stop
    sudo /etc/init.d/php5-fpm stop

    # 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 /etc/init.d/php5-fpm start
    sudo /etc/init.d/nginx start

    # Restart daemons.
    $ROOT/phabricator/bin/phd start

    # If running the notification server, start it.
    sudo $ROOT/phabricator/bin/aphlict start