Created
October 2, 2017 20:24
-
-
Save freephile/13d8a570144f6449509d9679f6f28b8a to your computer and use it in GitHub Desktop.
slicer.org scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unlike any other crontab you don't have to run the 'crontab' | |
# command to install the new version when you edit this file | |
# and other files in /etc/cron.d | |
# | |
# These files also have username fields, | |
# which user crontabs do not - making this more flexible as a solution to put | |
# all your crons in one place. | |
# | |
# System cron is in /etc/crontab and you generally don't want to edit that file | |
SHELL=/bin/sh | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin | |
# set the MAILTO variable so that I get notices of this job | |
MAILTO=greg@equality-tech.com | |
#### FORMAT of cron NOTE the user field here | |
# minute hour dayofmonth month dayofweek user command | |
# fetch any upstream edits to the static content of slicer.org into DOC_ROOT discarding STDOUT | |
*/5 * * * * root /var/www/slicer.org/bin/pull.github.sh > /dev/null | |
# */30 * * * * greg curl "https://issues.slicer.org/plugin.php?page=Source/import&id=all&api_key=<YOUR_API_KEY>" | |
# This job will keep MediaWiki happy | |
0 0 * * * root /usr/bin/php /var/www/slicer.org/www/w/maintenance/runJobs.php 2> /var/log/runJobs.log | |
10 0 * * * root /usr/bin/php /var/www/na-mic.org/www/w/maintenance/runJobs.php 2> /var/log/runJobs.log | |
#### Backup our databases every day | |
15 04 * * * root /root/bin/backup.db.sh slicer_slicerWiki_wiki | |
20 04 * * * root /usr/bin/find /backups -mtime +15 -exec rm {} \; | |
#### Renew our LetsEncrypt certificates automatically every week because they expire every 90 days | |
#### Hitting their server when the cert is valid is not a problem | |
05 04 * * 1 root /opt/certbot/certbot-auto renew -q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# @author Greg Rundlett <info@eQuality-Tech.com> | |
# This is a quick shell script to create a sql dump of your database. | |
# You may need to adjust the path of mysqldump, | |
# or sudo apt-get install mysqldump if it doesn't exist | |
# set -x # show execution | |
# set -v # show verbose | |
# To configure this script, | |
# you could hardcode which database to backup | |
# DB=wiki | |
# We'll make it so you can pass the database name as the first parameter | |
# to the script. If no parameter is passed, we'll prompt you for the name | |
DB=$1 | |
if [ $# -ne 1 ]; then | |
echo "Here are the current databases on the server" | |
mysql -u root --batch --skip-column-names -e 'show databases;' | |
echo "Enter the name of the database you want to backup" | |
read DB | |
fi | |
# We'll use a location that is exported to the host, so that our backups are | |
# accessible even if the virtual machine is no longer accessible. | |
# backupdir="/vagrant/mediawiki/backups"; | |
backupdir="/backups"; | |
if [ ! -d "$backupdir" ]; then | |
mkdir -p "$backupdir"; | |
fi | |
# we'll start with a default backup file named '01' in the sequence | |
backup="${backupdir}/dump-$(date +%F).$(hostname)-${DB}.01.sql"; | |
# and we'll increment the counter in the filename if it already exists | |
i=1 | |
filename=$(basename "$backup") # foo.txt (basename is everything after the last slash) | |
# shell parameter expansion see http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html | |
extension=${filename##*.} # .txt (filename with the longest matching pattern of *. being deleted) | |
file=${filename%.*} # foo (filename with the shortest matching pattern of .* deleted) | |
file=${file%.*} # repeat the strip to get rid of the counter | |
# file=${filename%.{00..99}.$extension} # foo (filename with the shortest matching pattern of .[01-99].* deleted) | |
while [ -f $backup ]; do | |
backup="$backupdir/${file}.$(printf '%.2d' $(( i+1 ))).${extension}" | |
i=$(( i+1 )) # increments $i | |
# note that i is naked because $(( expression )) is arithmetic expansion in bash | |
done | |
backedup=$(/usr/bin/mysqldump "$DB" > "$backup") | |
/usr/bin/mysqldump "$DB" > "$backup" || ( echo "Something went wrong with the backup" && exit 1 ) | |
verbose=false; | |
if $verbose; then | |
echo "backup created successfully" | |
ls -al "$backup"; | |
echo "A command such as" | |
echo "mysql -u root $DB < $backup" | |
echo "will restore the database from the chosen sql dump file" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
DOC_ROOT=/var/www/slicer.org/www | |
cd $DOC_ROOT | |
# we don't need to checkout the branch because we will only ever be on the branch | |
# git checkout gh-pages | |
git pull |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment