Using Git to Update + Backup site with one bash shell script …

You are expected to change variables/details for versions below.   This script will not create the backup directory.  Operator must create those directories manually.

Code is in /var/www/html/

nano up

Paste the following and adjust the variables

# 3.5.1+ (Build: 20180810)
tar -cvf /home/backup/m35/moodle-code-351+-$(date +%Y%m%d%-H%M%S).tar ./;
tar -cvf /home/backup/m35/moodle-data-min-351+-$(date +%Y%m%d%-H%M%S).tar /var/moodle35data/filedir;
mysqldump -u root -p moodle35 > /home/backup/m35/moodle351+-db-$(date +%Y%m%d%-H%M%S).sql;
ls -l /home/backup/m35/;
echo ‘Paused …’;
read $keypress;
git branch -a
php admin/cli/cron.php;
php admin/cli/maintenance.php –enable;
git pull;
php admin/cli/upgrade.php –non-interactive;
php admin/cli/maintenance.php –disable;
php admin/cli/purge_caches.php;
chown apache:apache * -R
fgrep ‘$release’ version.php

To execute:

cd /var/www/html/

source up [ENTER]

Protect up from browsers:

chmod go-rw up

chown root:root up

ls -l up

would look like:

-rwxr—–. 1 root root 803 Aug 15 18:12 up

Now login to the Moodle and go to Site Admin Menu -> Notifications (version is now?) – check updates.   Get updates to plugins.

The first line of this script was aquired via:

fgrep ‘$release’ version.php

while in the code directory.   Added to the top of the script as a reminder.

Leave a Reply