Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

  1. #11
    Join Date
    Jun 2007
    Location
    Paraparaumu, New Zealand
    Beans
    Hidden!

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    tl;dr
    Forum DOs and DON'Ts
    Please use CODE tags
    Including your email address in a post is not recommended
    My Blog

  2. #12
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,690
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Quote Originally Posted by lisati View Post
    tl;dr
    That's OK. Some people like to read such ramblings. It is mainly for my own documentation and future projects.

    Check Storage Space

    In favor of manage by exception, I wrote a script that can be scheduled to run daily to check the file systems to see if they are getting close to filling up and will automatically expand them a little bit and give you an email notice. Everything is done at the megabyte level. If you do not want the script to perform the increase, simply add a pound sign in front of the resize2fs command on line 64 to comment it out. Might also want to modify the log and email messages so it does not look like it actually "performed" the resize but instead is telling YOU how to perform the resize.

    Here are the lines I added to my crontab schedule which will check each file system I expect will grow on a daily basis @ 1am, 2am and 3am. I have them checking to see if we have less than 50 MB available and if so, it will try to increase by 50 MB.

    crontab
    Code:
    0 1 * * * /var/scripts/prod/check-storage.sh var 50 50 > /dev/null 2>&1
    0 2 * * * /var/scripts/prod/check-storage.sh bak 50 50 > /dev/null 2>&1
    0 3 * * * /var/scripts/prod/check-storage.sh temp 50 50 > /dev/null 2>&1
    /var/scripts/prod/check-storage.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : check-storage.sh
    ## Version       : 1.0
    ## Date          : 2012-05-11
    ## Author        : LHammonds
    ## Purpose       : Check available space for a file system and expand if necessary.
    ## Compatibility : Verified on Ubuntu Server 12.04 LTS
    ## Requirements  : None
    ## Run Frequency : Recommend once per day for each FS to monitor.
    ## Parameters    :
    ##    1 = (Required) File System name (e.g. var)
    ##    2 = (Required) File System Threshold in MB (e.g. 50)
    ##    3 = (Required) Amount to increase File System in MB (e.g. 50)
    ## Exit Codes    :
    ##    0 = Success (either nothing was done or FS expanded without error)
    ##    1 = ERROR: Missing or incorrect parameter(s)
    ##    2 = ERROR: Invalid parameter value(s)
    ##    4 = ERROR: Lock file detected
    ##    8 = ERROR: Resize2fs error
    ##   16 = SEVERE: No room to expand
    ##   32 = ERROR: Script not run by root user
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-05-11 LTH Created script.
    #############################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LOGFILE="${TEMPDIR}/check-storage.log"
    LOCKFILE="${TEMPDIR}/check-storage.lock"
    ErrorFlag=0
    ReturnCode=0
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    
    function f_cleanup()
    {
      if [ -f ${LOCKFILE} ];then
        ## Remove lock file so other check space jobs can run.
        rm ${LOCKFILE} 1>/dev/null 2>&1
      fi
      exit ${ErrorFlag}
    }
    
    function f_showhelp()
    {
      echo -e "\nUsage : ${SCRIPTNAME} FileSystemName ThresholdSizeInMB AmountToIncreaseByInMB\n"
      echo -e "\nExample: ${SCRIPTNAME} var 50 50\n"
    }
    
    function f_auto-increment()
    {
      let RoomInLV=${LVSize}-${FSSize}
      if [[ ${RoomInLV} -gt ${FSIncreaseBy} ]]; then
        ## There is room in the LV to increase space to the FS.
        resize2fs ${FSVol} ${NewFSSize}M
        ReturnCode=$?
        echo "`date +%Y-%m-%d_%H:%M:%S` --- resize2fs ${FSVol} ${NewFSSize}M, ReturnCode=${ReturnCode}" | tee -a ${LOGFILE}
        if [[ ${ReturnCode} -ne 0 ]]; then
          ## There was an error in resize2fs.
          return ${ReturnCode}
        fi
      else
        ## There is not enough room in the LV to increase space in the FS.
        return 50
      fi
      return 0
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    if [ -f ${LOCKFILE} ]; then
      # Lock file detected.  Abort script.
      echo "Check space script aborted"
      echo "This script tried to run but detected the lock file: ${LOCKFILE}"
      echo "Please check to make sure the file does not remain when check space is not actually running."
      f_sendmail "ERROR: check storage script aborted" "This script tried to run but detected the lock file: ${LOCKFILE}\n\nPlease check to make sure the file does not remain when check space is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LOCKFILE}'"
      ErrorFlag=4
      f_cleanup
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${SCRIPTNAME}" > ${LOCKFILE}
    fi
    
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo "ERROR: Root user required to run this script."
      echo ""
      ErrorFlag=32
      f_cleanup
    fi
    
    ## Check existance of required command-line parameters.
    case "$1" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSName=$1
        ;;
    esac
    case "$2" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSThreshold=$2
        ;;
    esac
    case "$3" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSIncreaseBy=$3
        ;;
    esac
    
    ## Check validity of File System name.
    case "${FSName}" in
      "var")
        FSVol="/dev/LVG/var"
        FSMap="/dev/mapper/LVG-var"
        ;;
      "bak")
        FSVol="/dev/LVG/bak"
        FSMap="/dev/mapper/LVG-bak"
        ;;
      "temp")
        FSVol="/dev/LVG/temp"
        FSMap="/dev/mapper/LVG-temp"
        ;;
      *)
        echo "ERROR: ${FSName} does not match a known file system defined in this script."
        f_showhelp
        ErrorFlag=2
        f_cleanup
        ;;
    esac
    
    ## Check validity of threshold value.
    test ${FSThreshold} -eq 0 1>/dev/null 2>&1
    if [[ $? -eq 2 ]]; then
      ## Threshold parameter is not an integer.
      echo "ERROR: ${FSThreshold} is not an integer."
      f_showhelp
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Check validity of increment value.
    test ${FSIncreaseBy} -eq 0 1>/dev/null 2>&1
    if [[ $? -eq 2 ]]; then
      ## FSIncreaseBy parameter is not an integer.
      echo "ERROR: ${FSIncreaseBy} is not an integer."
      f_showhelp
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Get available space for the file system.
    FSAvailable="`df --block-size=m ${FSMap} | awk '{ print $4 }' | tail -n 1 | sed 's/M//'`"
    
    ## Get the current size of the File System.
    FSSize="`df --block-size=m ${FSMap} | awk '{ print $2 }' | tail -n 1 | sed 's/M//'`"
    
    ## Get the current size of the Logical Volume for the File System
    LVSize="`lvs --noheadings --nosuffix --units=m ${FSMap} | awk '{ print $4}' | sed 's/[.].*//'`"
    
    ## Calculate the new size of the FS in case we need it.
    let NewFSSize=${FSSize}+${FSIncreaseBy}
    
    if [[ ${FSAvailable} -lt ${FSThreshold} ]]; then
      echo "`date +%Y-%m-%d_%H:%M:%S` - Starting expansion of ${FSVol}" | tee -a ${LOGFILE}
      echo "`date +%Y-%m-%d_%H:%M:%S` --- LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvail=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB" | tee -a ${LOGFILE}
      ## Run the auto-expansion function.
      f_auto-increment
      ReturnCode=$?
      case ${ReturnCode} in
      0)
        f_sendmail "NOTICE: File System Expanded" "${FSVol} was expanded because it was nearing max capacity.  Please review disk space usage and plan appropriately. LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB"
        ;;
      50)
        echo "`date +%Y-%m-%d_%H:%M:%S` - SEVERE: No room to expand ${FSVol}" | tee -a ${LOGFILE}
        ErrorFlag=16
        f_sendmail "SEVERE: No room to expand ${FSVol}" "There is not enough room in the Logical Volume to expand the ${FSVol} File System.  Immediate action is required.  Make sure there is free space in the Volume Group 'LVG' and then expand the Logical Volume...then expand the File System.\n\nLVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB.\n\nType 'vgs' to see if there is any free space in the Volume Group which can be given to the Logical Volume.\n\nType 'lvs' to see the current sizes of the LVs.\n\nType 'lvdisplay' to see a list of Logical Volumes so you can get the LV Name which is used in the lvextend and resize2fs commands.\n\nType 'lvextend -L+50M /dev/LVG/var' if you want to extend the var Logical Volume by 50 megabytes (assuming there is 50MB available in the Volume Group).\n\nType 'df --block-size=m' to see a list of file systems and their associated size and available space.\n\nType 'resize2fs /dev/LVG/var ${NewFSSize}M' to set the size of var to ${NewFSSize} megabytes. Make sure you set the size to the desired end-result which should be LARGER than the current FS size so you do not lose data."
        ;;
      *)
        echo "`date +%Y-%m-%d_%H:%M:%S` - ERROR: Expansion failure for ${FSVol}" | tee -a ${LOGFILE}
        ErrorFlag=8
        f_sendmail "ERROR: File System Expansion Failed" "${FSVol} Expansion failed with return code of ${ReturnCode}.  LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB"
        ;;
      esac
      echo "`date +%Y-%m-%d_%H:%M:%S` - Finished expansion of ${FSVol}" | tee -a ${LOGFILE}
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` - ${FSVol} ${FSAvailable}M>${FSThreshold}M No action required." | tee -a ${LOGFILE}
    fi
    
    ## Perform cleanup routine.
    f_cleanup
    Here is the typical output when it does not have to increase the FS:

    /var/temp/check-storage.log
    Code:
    2012-05-01_01:00:00 - /dev/LVG/var 44M>5M No action required.
    2012-05-01_02:00:00 - /dev/LVG/bak 91M>5M No action required.
    2012-05-01_03:00:00 - /dev/LVG/temp 93M>5M No action required.
    2012-05-02_01:00:00 - /dev/LVG/var 44M>5M No action required.
    2012-05-02_02:00:00 - /dev/LVG/bak 91M>5M No action required.
    2012-05-02_03:00:00 - /dev/LVG/temp 93M>5M No action required.
    2012-05-03_01:00:00 - /dev/LVG/var 44M>5M No action required.
    2012-05-03_02:00:00 - /dev/LVG/bak 91M>5M No action required.
    2012-05-03_03:00:00 - /dev/LVG/temp 93M>5M No action required.
    Here is a sample of what the log will look like when it perform increases...notice how I had to increase the threshold in order for it to fire off the increase (but it still just issued a single megabyte increase):

    /var/temp/check-storage.log
    Code:
    2012-05-02_01:00:00 - Starting expansion of /dev/LVG/var
    2012-05-02_01:00:00 --- LVSize=75MB, FSSize=50MB, FSAvail=44MB, FSThreshold=55MB, IncreaseBy=1MB
    2012-05-02_01:00:00 --- resize2fs /dev/LVG/var 51, ReturnCode=0
    2012-05-02_01:00:00 - Finished expansion of /dev/LVG/var
    2012-05-02_02:00:00 - Starting expansion of /dev/LVG/bak
    2012-05-02_02:00:00 --- LVSize=125MB, FSSize=99MB, FSAvail=91MB, FSThreshold=100MB, IncreaseBy=1MB
    2012-05-02_02:00:00 --- resize2fs /dev/LVG/bak 100, ReturnCode=0
    2012-05-02_02:00:00 - Finished expansion of /dev/LVG/bak
    2012-05-02_03:00:00 - Starting expansion of /dev/LVG/temp
    2012-05-02_03:00:00 --- LVSize=125MB, FSSize=99MB, FSAvail=93MB, FSThreshold=100MB, IncreaseBy=1MB
    2012-05-02_03:00:00 --- resize2fs /dev/LVG/temp 100, ReturnCode=0
    2012-05-02_03:00:00 - Finished expansion of /dev/LVG/temp

  3. #13
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,690
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    MediaWiki Backup

    There are various methods of backup that can be utilized but for this server, I will simply use RSync and tar.

    RSync will mirror the files in the production folder to a local backup folder. The archive will be created from this backup folder.

    Here are the folders I consider important that will be included in the backup:

    Data Folders:
    SRV-Wiki: /backup (which contains a mirror of /var/www)

    Config Folders and files:
    SRV-Wiki: /var/log/apache2/
    SRV-Wiki: /etc/apache2/
    SRV-Wiki: /etc/php5/
    SRV-Wiki: /etc/network/interfaces
    SRV-Wiki: /etc/hosts

    Remote Data:
    SRV-MYSQL: MediaWiki Database

    The backup of the web site will be fairly simplistic. However, since there are multiple servers involved, the backup will need to be synchronized for the web files, uploads and the remote database.

    A crontab schedule will be used to schedule the local backups and when the backup is initiated on the local server, a special file will be sent to the remote database server so it will trigger a backup on the database that corresponds to this server (mediawiki).

    The bulk of the data will be in /var/www and rsync will be used to copy any files from that folder to the backup folder. The benefit and beauty of using rsync in this way is that it will only copy what has changed since the last backup/sync. That means it will run VERY quickly even if your www folder has gigs of data in it. The other miscellaneous folders will be archived directly from their source location which will not be much in terms of size.

    /var/scripts/prod/mediawiki-backup.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : mediawiki-backup.sh
    ## Version       : 1.0
    ## Date          : 2012-05-15
    ## Author        : LHammonds
    ## Compatibility : Ubuntu Server 12.04 LTS
    ## Purpose       : Backup web server while online.
    ## Run Frequency : One or multiple times per day.
    ## Exit Codes    : (if multiple errors, value is the addition of codes)
    ##   0 = Success
    ##   1 = rsync failure
    ##   2 = Archive creation failure
    ##   4 = Remote copy failure
    ##   8 = Cannot connect to MySQL NFS mount
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-05-15 LTH Created script.
    #############################################
    
    ## Import common variables and functions. ##
    source /var/scripts/common/standard.conf
    
    LOGFILE="${TEMPDIR}/mediawiki-backup.log"
    TARGET="${BACKUPDIR}/mediawiki"
    LOCKFILE="${TEMPDIR}/mediawiki-backup.lock"
    ARCHIVEFILE="`date +%Y-%m-%d-%H-%M`_mediawiki-backup.${ARCHIVEMETHOD}"
    SOURCES="/backup /var/log/apache2/ /etc/apache2/ /etc/php5/ /etc/network/interfaces /etc/hosts"
    ERRORFLAG=0
    RETURNVALUE=0
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    function f_PurgeOldestArchive()
    {
      ## Purpose: Delete the oldest archive on the remote site.
      ## Return values:
      ##    0 = Success
      ##    1 = Cannot delete file
      ##    9 = Configuration error, path empty
    
      ## Variable Error Check. *
      if [ ${OFFSITEBACKDIR} = "" ]; then
        ## Make darn sure the path is not empty since we do NOT
        ## want to start purging files from a random location.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- Purge error: OFFSITEBACKDIR site variable is empty!" >> ${LOGFILE}
        return 9
      fi
      ## Get the name of the oldest file.
      OLDESTFILE=`ls -1t ${OFFSITEBACKDIR} | tail -1`
      if [ "${OLDESTFILE}" = "" ]; then
        ## Error. Filename variable empty.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- Purge error: OLDESTFILE variable is empty." >> ${LOGFILE}
        return 9
      else   
        FILESIZE=`ls -lak "${OFFSITEBACKDIR}/${OLDESTFILE}" | awk '{ print $5 }' | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`
        echo "`date +%Y-%m-%d_%H:%M:%S` --- Purging old file: ${OFFSITEBACKDIR}/${OLDESTFILE}, Size = ${FILESIZE} kb" >> ${LOGFILE}
        rm "${OFFSITEBACKDIR}/${OLDESTFILE}"
        if [ -f "${OFFSITEBACKDIR}/${OLDESTFILE}" ]; then
          ## File still exists.  Return error.
          return 1
        else
          return 0
        fi
      fi
    }
    
    function f_cleanup()
    {
      if [ -f ${LOCKFILE} ];then
        ## Remove lock file so other backup jobs can run.
        rm "${LOCKFILE}" 1>/dev/null 2>&1
      fi
      echo "`date +%Y-%m-%d_%H:%M:%S` - MediaWiki backup exit code: ${ERRORFLAG}" >> ${LOGFILE}
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    ## Binaries ##
    TAR="$(which tar)"
    MY7ZIP="$(which 7za)"
    RSYNC="$(which rsync)"
    
    if [ -f ${LOCKFILE} ]; then
      ## Script lock file detected.  Abort script.
      f_sendmail "MediaWiki Backup Aborted - Lock File" "This script tried to run but detected the lock file: ${LOCKFILE}\n\nPlease check to make sure the file does not remain when backup is not actually running."
      exit 1
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${SCRIPTNAME}" > ${LOCKFILE}
    fi
    
    StartTime="$(date +%s)"
    echo "`date +%Y-%m-%d_%H:%M:%S` - Backup started." >> ${LOGFILE}
    
    ## Connect to the MySQL server to kick-off a remote database backup.
    mount srv-mysql:/srv/samba/share /mnt/srv-mysql
    if [ -f /mnt/srv-mysql/offline.txt ];then
      ## The mount command did not work.
      ERRORFLAG=${ERRORFLAG} + 8
    else
      ## Create the key file to trigger a backup of the database.
      echo "Time to backup MediaWiki!" > /mnt/srv-mysql/mediawiki
      umount /mnt/srv-mysql
    fi
    
    ## Output the version information to a text file which will be included in the backup.
    if [ -f "${APPDIR}/version-info.txt" ]; then
      rm "${APPDIR}/version-info.txt"
    fi
    lsb_release -cd >> ${APPDIR}/version-info.txt
    apache2 -v >> ${APPDIR}/version-info.txt
    php -i >> ${APPDIR}/version-info.txt
    
    ## Check destination folder.  Create folder structure if not present.
    if [ ! -d "${TARGET}" ]; then
      mkdir -p ${TARGET}
    fi
    
    ## Synchronize files to backup folder.
    ${RSYNC} -apogHK --delete --exclude=*.pid ${APPDIR} ${TARGET} 1>/dev/null 2>&1
    RETURNVALUE=$?
    if [ ${RETURNVALUE} -ne 0 ]; then
      ## ERROR: Send email notification.
      echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Backup failed. ${APPDIR} -> ${TARGET}" >> ${LOGFILE}
      f_sendmail "Backup Failure - rsync" "ERROR: Backup failed. ${APPDIR} -> ${TARGET}, RETURN VALUE = ${RETURNVALUE}"
      ERRORFLAG=${ERRORFLAG} + 1
    fi
    
    ## Compress the backup into a single file based on archive method specified.
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Compressing archive: ${TEMPDIR}/${ARCHIVEFILE}" >> ${LOGFILE}
    case "${ARCHIVEMETHOD}" in
    tar.7z)
      ${TAR} -cpf - ${SOURCES} | ${MY7ZIP} a -si -mx=9 -w${TEMPDIR} ${TEMPDIR}/${ARCHIVEFILE} 1>/dev/null 2>&1
      RETURNVALUE=$?
      ## Restore using one of the following commands (do not uncomment, only for notation):
      ## 7za x -so -w/tmp ${TEMPDIR}/${ARCHIVEFILE} | tar -C / -xf -
      ## 7za x -so -w/tmp ${TEMPDIR}/${ARCHIVEFILE} | tar -C ${TEMPDIR}/restore --strip-components=1 -xf -
      ;;
    tgz)
      ${TAR} -cpzf ${TEMPDIR}/${ARCHIVEFILE} ${SOURCES} 1>/dev/null 2>&1
      RETURNVALUE=$?
      ## Restore using one of the following commands (do not uncomment, only for notation):
      ## tar -C / -xzf ${TEMPDIR}/${ARCHIVEFILE}
      ## tar -C ${TEMPDIR}/restore --strip-components=1 -xzf ${TEMPDIR}/${ARCHIVEFILE}
      ;;
    *)
      ${TAR} -cpzf ${TEMPDIR}/${ARCHIVEFILE} ${SOURCES} 1>/dev/null 2>&1
      RETURNVALUE=$?
      ;;
    esac
    
    if [ ${RETURNVALUE} -ne 0 ]; then
      ## tar command failed.  Send warning email.
      f_sendmail "MediaWiki Backup Failure - tar" "tar failed with return value of ${RETURNVALUE}"
      ERRORFLAG=$((${ERRORFLAG} + 2))
    fi
    
    ## Mount the remote folder. ##
    f_mount
    
    if [ ! -f ${OFFSITETESTFILE} ]; then
      ## Could not find expected file on remote site.  Assuming failed mount.
      ERRORFLAG=$((${ERRORFLAG} + 16))
      echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Cannot detect remote location: ${OFFSITETESTFILE}" >> ${LOGFILE}
      f_emergencyexit ${ERRORFLAG}
    fi
    
    FREESPACE=`df -k ${OFFSITEDIR} | grep ${OFFSITEDIR} | awk '{ print $3 }'`
    BACKUPSIZE=`ls -lak "${TEMPDIR}/${ARCHIVEFILE}" | awk '{ print $5 }'`
    
    ## Make sure space is available on the remote server to copy the file.
    if [ ${FREESPACE} -lt ${BACKUPSIZE} ]; then
      ## Not enough free space available.  Purge existing backups until there is room.
      ENOUGHSPACE=0
      while [ ${ENOUGHSPACE} -eq 0 ]
      do
        f_PurgeOldestArchive
        RETURNVALUE=$?
        case ${RETURNVALUE} in
        1)
          ## Cannot purge archives to free up space.  End program gracefully.
          echo "`date +%Y-%m-%d_%H:%M:%S` - ERROR: Not enough free space on ${OFFSITEBACKDIR} and cannot purge old archives.  Script aborted." >> ${LOGFILE}
          ## Stop and exit the script with an error code.
          ERRORFLAG=$((${ERRORFLAG} + 4))
          f_emergencyexit ${ERRORFLAG}
          ;;
        9)
          ## Configuration error, end program gracefully.
          echo "`date +%Y-%m-%d_%H:%M:%S` - ERROR: Configuration problem. Script aborted." >> ${LOGFILE}
          ## Stop and exit the script with an error code.
          ERRORFLAG=$((${ERRORFLAG} + 8))
          f_emergencyexit ${ERRORFLAG}
          ;;
        esac
        FREESPACE=`df -k ${OFFSITEDIR} | grep ${OFFSITEDIR} | awk '{ print $3 }'`
        if [ ${FREESPACE} -gt ${BACKUPSIZE} ]; then
          ## Enough space is now available.
          ENOUGHSPACE=1
        else
          ## Not enough space is available yet.
          ENOUGHSPACE=0
        fi
      done
    fi
    
    ## Copy the backup to an offsite storage location.
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Copying archive file to offsite location." >> ${LOGFILE}
    cp ${TEMPDIR}/${ARCHIVEFILE} ${OFFSITEDIR}/${ARCHIVEFILE} 1>/dev/null 2>&1
    if [ ! -f ${OFFSITEDIR}/${ARCHIVEFILE} ]; then
      ## NON-FATAL ERROR: Copy command did not work.  Send email notification.
      echo "`date +%Y-%m-%d_%H:%M:%S` --- WARNING: Remote copy failed. ${OFFSITEDIR}/${ARCHIVEFILE} does not exist!" >> ${LOGFILE}
      f_sendmail "MediaWiki Backup Failure - Remote Copy" "Remote copy failed. ${OFFSITEDIR}/${ARCHIVEFILE} does not exist\n\nBackup file still remains in this location: ${HOSTNAME}:${TEMPDIR}/${ARCHIVEFILE}"
    else
      ## Remove local copy of the compressed backup file
      rm "${TEMPDIR}/${ARCHIVEFILE}"
    fi
    
    ## Unmount the Windows shared folder.
    f_umount
    
    ## Calculate total time for backup.
    FinishTime="$(date +%s)"
    ElapsedTime="$(expr ${FinishTime} - ${StartTime})"
    Hours=$((${ElapsedTime} / 3600))
    ElapsedTime=$((${ElapsedTime} - ${Hours} * 3600))
    Minutes=$((${ElapsedTime} / 60))
    Seconds=$((${ElapsedTime} - ${Minutes} * 60))
    
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Total backup time: ${Hours} hour(s) ${Minutes} minute(s) ${Seconds} second(s)" >> ${LOGFILE}
    
    echo "`date +%Y-%m-%d_%H:%M:%S` - MediaWiki backup completed." >> ${LOGFILE}
    
    ## Perform cleanup routine.
    f_cleanup
    ## Exit with the combined return code value.
    exit ${ERRORFLAG}
    Here is some sample output from the log file.

    /temp/mediawiki-backup.log
    Code:
    2012-05-15_10:17:57 - Backup started.
    2012-05-15_10:17:58 --- Compressing archive: /temp/2012-05-15-10-17_mediawiki-backup.tar.7z
    2012-05-15_10:18:49 --- Copying archive file to offsite location.
    2012-05-15_10:18:49 --- Total backup time: 0 hour(s) 0 minute(s) 52 second(s)
    2012-05-15_10:18:49 - MediaWiki backup completed.
    2012-05-15_10:18:49 - MediaWiki backup exit code: 0
    2012-05-15_10:23:16 - Backup started.
    2012-05-15_10:23:16 --- Compressing archive: /temp/2012-05-15-10-23_mediawiki-backup.tar.7z
    2012-05-15_10:24:05 --- Copying archive file to offsite location.
    2012-05-15_10:24:26 --- Total backup time: 0 hour(s) 1 minute(s) 10 second(s)
    2012-05-15_10:24:26 - MediaWiki backup completed.
    2012-05-15_10:24:26 - MediaWiki backup exit code: 0
    2012-05-15_10:38:41 - Backup started.
    2012-05-15_10:38:41 --- Compressing archive: /temp/2012-05-15-10-38_mediawiki-backup.tar.7z
    2012-05-15_10:39:31 --- Copying archive file to offsite location.
    2012-05-15_10:39:57 --- Total backup time: 0 hour(s) 1 minute(s) 16 second(s)
    2012-05-15_10:39:57 - MediaWiki backup completed.
    2012-05-15_10:39:57 - MediaWiki backup exit code: 0
    2012-05-15_10:44:37 - Backup started.
    2012-05-15_10:44:39 --- Compressing archive: /temp/2012-05-15-10-44_mediawiki-backup.tar.7z
    2012-05-15_10:45:28 --- Copying archive file to offsite location.
    2012-05-15_10:45:59 --- Total backup time: 0 hour(s) 1 minute(s) 22 second(s)
    2012-05-15_10:45:59 - MediaWiki backup completed.
    2012-05-15_10:45:59 - MediaWiki backup exit code: 0
    Here is the top part of the version info file included in each backup.

    /var/www/version-info.txt
    Code:
    Description:    Ubuntu 12.04 LTS
    Codename:    precise
    Server version: Apache/2.2.22 (Ubuntu)
    Server built:   Feb 13 2012 01:51:50
    phpinfo()
    PHP Version => 5.3.10-1ubuntu3.1
    
    System => Linux srv-wiki 3.2.0-24-generic #37-Ubuntu SMP Wed Apr 25 08:43:22 UTC 2012 x86_64
    Build Date => May  4 2012 02:18:29

  4. #14
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,690
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Crontab

    I would not advise anyone to ever "edit" a live crontab schedule by typing "crontab -e" but rather edit a saved schedule file and then load the schedule file. This will allow you to make backups of the schedule so you can always go back to a known-good schedule or at least back to the way it was before you made a change...assuming you always work with a copy of the schedule 1st.

    Here is my root crontab scheduling file:

    /var/scripts/data/crontab.root

    Code:
    ########################################
    # Name: Crontab Schedule for root user
    # Author: LHammonds
    ############# Update Log ###############
    # 2012-05-15 - LTH - Created schedule
    ########################################
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # m h dom mon dow command
    
    #
    # Adjust the time clock
    #
    0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1
    #
    # Backup MediaWiki
    #
    0 22 * * * /var/scripts/prod/mediawiki-backup.sh > /dev/null 2>&1
    #
    # Daily check for available space on /var
    #
    0 1 * * * /var/scripts/prod/check-storage.sh opt 50 50 > /dev/null 2>&1
    #
    # Daily check for available space on /backup
    #
    0 2 * * * /var/scripts/prod/check-storage.sh bak 50 50 > /dev/null 2>&1
    #
    # Daily check for available space on /temp
    #
    0 3 * * * /var/scripts/prod/check-storage.sh temp 50 50 > /dev/null 2>&1
    Once you have created the file, make sure appropriate permissions are set by typing the following:
    Code:
    chown root:root /var/scripts/data/crontab.root
    chmod 0600 /var/scripts/data/crontab.root
    To enable the root schedule using this file, type the following:

    Code:
    crontab -u root /var/scripts/data/crontab.root
    To disable the root schedule, type the following:
    Code:
    touch /tmp/deleteme
    crontab -u root /tmp/deleteme
    rm /tmp/deleteme
    If you need to modify the schedule, make a backup copy 1st. For example:

    Code:
    cp /var/scripts/data/crontab.root /var/scripts/data/2011-11-28-crontab.root
    vi /var/scripts/data/crontab.root (make your changes)
    crontab -u root /var/scripts/data/crontab.root
    This concludes my documentation on how I setup a MediaWiki server.

    If you notice any problems, please reply here and let me know.

    Thanks,
    LHammonds

  5. #15
    Join Date
    Oct 2011
    Location
    /root
    Beans
    956
    Distro
    Ubuntu

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Very well written! Great work. I vote to sticky


  6. #16
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,690
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    APT Upgrade

    Here is a script that can be scheduled to run daily to check for updates and then install them if available.

    This is the line you put in crontab to have the script once per day @ 3am.

    /var/scripts/data/crontab.root
    Code:
    0 3 * * * /var/scripts/prod/apt-upgrade.sh > /dev/null 2>&1
    /var/scripts/prod/apt-upgrade.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : apt-upgrade.sh
    ## Version       : 1.0
    ## Date          : 2012-06-01
    ## Author        : LHammonds
    ## Purpose       : Keep system updated (rather than use unattended-upgrades)
    ## Compatibility : Verified on Ubuntu Server 12.04 LTS
    ## Requirements  : Sendemail, run as root
    ## Run Frequency : Recommend once per day.
    ## Parameters    : None
    ## Exit Codes    :
    ##    0 = Success
    ##    1 = ERROR: Lock file detected.
    ##    2 = ERROR: Not run as root user.
    ##    4 = ERROR: Aptitude update Error.
    ##    8 = ERROR: Aptitude safe-upgrade Error.
    ##   16 = ERROR: Aptitude autoclean Error.
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-06-01 LTH Created script.
    #############################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LOGFILE="${LOGDIR}/apt-upgrade.log"
    LOCKFILE="${TEMPDIR}/apt-upgrade.lock"
    ErrorFlag=0
    ReturnCode=0
    APTCMD="$(which aptitude)"
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    
    function f_cleanup()
    {
      if [ -f ${LOCKFILE} ];then
        ## Remove lock file so subsequent jobs can run.
        rm ${LOCKFILE} 1>/dev/null 2>&1
      fi
      exit ${ErrorFlag}
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    if [ -f ${LOCKFILE} ]; then
      # Lock file detected.  Abort script.
      echo "** Script aborted **"
      echo "This script tried to run but detected the lock file: ${LOCKFILE}"
      echo "Please check to make sure the file does not remain when check space is not actually running."
      f_sendmail "ERROR: Script aborted" "This script tried to run but detected the lock file: ${LOCKFILE}\n\nPlease check to make sure the file does not remain when check space is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LOCKFILE}'"
      ErrorFlag=1
      f_cleanup
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${SCRIPTNAME}" > ${LOCKFILE}
    fi
    
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo -e "ERROR: Root user required to run this script.\n"
      ErrorFlag=2
      f_cleanup
    fi
    
    echo "`date +%Y-%m-%d_%H:%M:%S` - Begin script." >> ${LOGFILE}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Aptitude Update" >> ${LOGFILE}
    ${APTCMD} update > /dev/null 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorFlag=4
      f_cleanup
    fi
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Aptitude Safe-Upgrade" >> ${LOGFILE}
    echo "--------------------------------------------------" >> ${LOGFILE}
    ${APTCMD} safe-upgrade --assume-yes --target-release `lsb_release -cs`-security >> ${LOGFILE} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorFlag=8
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LOGFILE}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Aptitude Autoclean" >> ${LOGFILE}
    echo "--------------------------------------------------" >> ${LOGFILE}
    ${APTCMD} autoclean >> ${LOGFILE} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorFlag=16
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LOGFILE}
    echo "`date +%Y-%m-%d_%H:%M:%S` - End script." >> ${LOGFILE}
    
    ## Perform cleanup routine.
    f_cleanup
    Here is the typical output:

    /var/log/apt-upgrade.log
    Code:
    2012-06-01_09:31:19 - Begin script.
    2012-06-01_09:31:19 --- Aptitude Update
    2012-06-01_09:32:01 --- Aptitude Safe-Upgrade
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    No packages will be installed, upgraded, or removed.
    0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0 B of archives. After unpacking 0 B will be used.
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    --------------------------------------------------
    2012-06-01_09:32:03 --- Aptitude Autoclean
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    Freed 0 B of disk space
    --------------------------------------------------
    2012-06-01_09:32:04 - End script.
    2012-06-02_03:00:01 - Begin script.
    2012-06-02_03:00:01 --- Aptitude Update
    2012-06-02_03:00:26 --- Aptitude Safe-Upgrade
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    The following packages will be upgraded:
      grub-common grub-pc grub-pc-bin grub2-common libcups2 libgcrypt11
    6 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Need to get 3,611 kB of archives. After unpacking 59.4 kB will be freed.
    Writing extended state information...
    Get: 1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libgcrypt11 amd64 1.5.0-3ubuntu0.1 [280 kB]
    Get: 2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libcups2 amd64 1.5.3-0ubuntu1 [171 kB]
    Get: 3 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub-pc amd64 1.99-21ubuntu3.1 [140 kB]
    Get: 4 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub-pc-bin amd64 1.99-21ubuntu3.1 [861 kB]
    Get: 5 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub2-common amd64 1.99-21ubuntu3.1 [94.3 kB]
    Get: 6 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main grub-common amd64 1.99-21ubuntu3.1 [2,066 kB]
    Fetched 3,611 kB in 3s (941 kB/s)
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    dpkg-preconfigure: unable to re-open stdin:
    (Reading database ... 61584 files and directories currently installed.)
    Preparing to replace libgcrypt11 1.5.0-3 (using .../libgcrypt11_1.5.0-3ubuntu0.1_amd64.deb) ...
    Unpacking replacement libgcrypt11 ...
    Preparing to replace libcups2 1.5.2-9ubuntu1 (using .../libcups2_1.5.3-0ubuntu1_amd64.deb) ...
    Unpacking replacement libcups2 ...
    Preparing to replace grub-pc 1.99-21ubuntu3 (using .../grub-pc_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub-pc ...
    Preparing to replace grub-pc-bin 1.99-21ubuntu3 (using .../grub-pc-bin_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub-pc-bin ...
    Preparing to replace grub2-common 1.99-21ubuntu3 (using .../grub2-common_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub2-common ...
    Preparing to replace grub-common 1.99-21ubuntu3 (using .../grub-common_1.99-21ubuntu3.1_amd64.deb) ...
    Unpacking replacement grub-common ...
    Processing triggers for man-db ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    Processing triggers for install-info ...
    Processing triggers for ureadahead ...
    Setting up libgcrypt11 (1.5.0-3ubuntu0.1) ...
    Setting up libcups2 (1.5.3-0ubuntu1) ...
    Setting up grub-common (1.99-21ubuntu3.1) ...
    Installing new version of config file /etc/grub.d/10_linux ...
    Setting up grub2-common (1.99-21ubuntu3.1) ...
    Setting up grub-pc-bin (1.99-21ubuntu3.1) ...
    Setting up grub-pc (1.99-21ubuntu3.1) ...
    debconf: unable to initialize frontend: Dialog
    debconf: (TERM is not set, so the dialog frontend is not usable.)
    debconf: falling back to frontend: Readline
    debconf: unable to initialize frontend: Readline
    debconf: (This frontend requires a controlling tty.)
    debconf: falling back to frontend: Teletype
    Installation finished. No error reported.
    Generating grub.cfg ...
    Found linux image: /boot/vmlinuz-3.2.0-24-generic
    Found initrd image: /boot/initrd.img-3.2.0-24-generic
    Found linux image: /boot/vmlinuz-3.2.0-23-generic
    Found initrd image: /boot/initrd.img-3.2.0-23-generic
    Found memtest86+ image: /memtest86+.bin
    done
    Processing triggers for libc-bin ...
    ldconfig deferred processing now taking place
    ldconfig deferred processing now taking place
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    --------------------------------------------------
    2012-06-02_03:00:43 --- Aptitude Autoclean
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Reading extended state information...
    Initializing package states...
    Freed 0 B of disk space
    --------------------------------------------------
    2012-06-02_03:00:44 - End script.
    Last edited by LHammonds; June 2nd, 2012 at 03:40 PM.

  7. #17
    Join Date
    Jan 2008
    Beans
    39

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Wow, just wow!

    Thanks very much for covering all this.
    I have learned quite a bit from reading this thread alone.

    Do you have list type of information saved on your own site anywhere or any more fully-informative type guides?

  8. #18
    Join Date
    Mar 2012
    Beans
    30

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Just incredible! So much information here... I could spend just a week reading through everything here and trying to soak it all in!

    THANK YOU FOR ALL YOU HARD WORK!

  9. #19
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,690
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Quote Originally Posted by fubofo View Post
    Do you have list type of information saved on your own site anywhere or any more fully-informative type guides?
    I do have a site where I have a ton of tutorials, but they are not related to Linux. The ones related to Linux are in my sig.

    --------------

    Document revised using the sudo su method to temporarily gain root-level access rather than setting a password on the root account.

    The next change will be the setup of the operating system to be generalized a bit and pulled into a different document and then referred to rather than trying to update OS-specific changes in all my different threads.

    EDIT: Here is my website. You can find the tutorial section under Miscellaneous.

    LHammonds
    Last edited by LHammonds; June 19th, 2012 at 09:31 AM.

  10. #20
    Join Date
    Jan 2008
    Beans
    39

    Re: My Notes for Installing MediaWiki on Ubuntu Server 12.04 LTS

    Cheers LHammonds, this is indeed invaluable info. Also, I NEVER heard of Nagios before....seems like a fantastic monitoring tool.

    What is your site (Linux or not)?
    maybe you should consider making some Linux tutorials

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •