Last active
March 3, 2021 23:48
-
-
Save kevinski303/df192fb612a6188becb1108942fbdf8d to your computer and use it in GitHub Desktop.
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 | |
# Make sure only root can run our script | |
if [ "$(id -u)" != "0" ]; then | |
echo "Diese Script muss als root ausgeführt werden" 1>&2 | |
exit 1 | |
fi | |
DATUM=`date +%Y%m%d` | |
before=`date +%Y%m%d -d "yesterday"` | |
timestamp=$(date -u) | |
ls900sql=/wiki/maintenance/migration/ls900_wiki.sql.gz | |
ls900db=ls900_wiki | |
temppath=/wiki/maintenance/migration/tmp | |
ls900imagesarch=/wiki/maintenance/migration/images_ls900.tar.gz | |
ls900imagestemp=/wiki/maintenance/migration/tmp/var/wiki/webroot/ls900/images/ | |
ls900imagespath=/wiki/webroot/ls900/images/ | |
logfile=/wiki/maintenance/logs/nightlyrestore | |
#Create logfile | |
if test -f "$logfile"; | |
then | |
rm -f $logfile; | |
fi | |
touch $logfile; | |
chmod 775 $logfile; | |
echo " " >> $logfile; | |
echo "[:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::]" >> $logfile; | |
echo "[... NIGHTLY MIGRATION YMD: $DATUM // DATENSTAND LS900 WIKI YMD: $before ::]" >> $logfile; | |
echo "[:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::]" >> $logfile; | |
echo " " >> $logfile; | |
#Check if tmp exists | |
if [ ! -d "$temppath" ]; | |
then | |
echo " " >> $logfile; | |
echo "$timestamp [...creating " $temppath " ..]" >> $logfile; | |
mkdir $temppath; | |
fi | |
#Restore LS900DB | |
if test -f $ls900sql; | |
then | |
echo " " >> $logfile; | |
echo "$timestamp [...Restoring LS900 Database...]" >> $logfile; | |
zcat $ls900sql | mysql -uroot -pWikiDevelopment $ls900db >> $logfile; | |
#Extract pictures and move to Webfolder | |
if test -f $ls900imagesarch; | |
then | |
echo " " >> $logfile; | |
echo "$timestamp [...Extracting Images to temporary path...]" >> $logfile; | |
tar -xvf $ls900imagesarch -C $temppath >> $logfile; | |
echo " " >> $logfile; | |
echo "$timestamp [...Synchronizing images path to Destination...]" >> $logfile; | |
rsync -ah --progress $ls900imagestemp $ls900imagespath >> $logfile; | |
#Fixing Permission on webroot folder | |
echo " " >> $logfile; | |
echo "$timestamp [...fixing permissions on webroot folder...]" >> $logfile; | |
chown -R www-data:www-data /wiki/webroot/ls900 >> $logfile; | |
else | |
echo " " >> $logfile; | |
echo "$timestamp [...WARNING " $ls900imagesarch " doesnt exist, restore process will continue...]" >> $logfile; | |
fi | |
#Run PHP Update, rebuld data and Restart Services | |
echo " " >> $logfile; | |
echo "$timestamp [...Running php maintenance/update.php...]" >> $logfile; | |
php /wiki/webroot/ls900/maintenance/update.php >> $logfile; | |
echo " " >> $logfile; | |
echo "$timestamp [...Running php maintenance/rebuildall.php...]" >> $logfile; | |
php /wiki/webroot/ls900/maintenance/rebuildall.php >> $logfile; | |
echo " " >> $logfile; | |
echo "$timestamp [.. Running php extensions/semantivmediawiki/maintenance/rebuildata.php...]" >> $logfile; | |
php /wiki/webroot/ls900/extensions/SemanticMediaWiki/maintenance/rebuildData.php -v >> $logfile; | |
echo " " >> $logfile; | |
echo "$timestamp [...Restarting apache and parsoid service...]" >> $logfile; | |
systemctl restart apache2 >> $logfile; | |
systemctl restart parsoid >> $logfile; | |
#Clean up Files | |
echo " " >> $logfile; | |
echo "$timestamp [...Cleaning up temporary files and archives...]" >> $logfile; | |
rm -rf /wiki/maintenance/migration/tmp/* >> $logfile; | |
#rm $ls900imagesarch >> $logfile; | |
#rm $ls900sql >> $logfile; | |
else | |
echo " " >> $logfile; | |
echo "$timestamp [...WARNING" $ls900sql "doesnt exist, Restore process will be terminated...]" >> $logfile; | |
fi | |
#Copy logfile to readable webpath | |
cat $logfile > /wiki/webroot/ls900migrationlog.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment