We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18942
    • 1 Posts
    What is the fastest and easiest way to backup a system running MODx just using a cron script?

    I’m thinking, shut down Apache and MySQL and copy the whole shooting match somewhere then restart MySQL and Apache - followed by an export of the copied directories/database. This would give us an entirely consistent snapshot backup which could be restored without qualm.

    In discussion with my sysadmin, he raises a question of synchronisation between MODx’s info in the database and the filesystem if we try to keep things running. He is being a bit theoretical about restoring from backup if there are any differences between the filesystem and what MODx thinks is there.

    I scanned the FAQ and searched for "server backup" and "backup" but didn’t see anything I could relate to this.

    Thanks for any advice

    Mike


      • 1122
      • 209 Posts
      There is no need of shutting down anything -- simply use mysqldump and the database snapshot will be consistent. Here goes a skeleton of shell script for running from within cron.daily; adjust it to fit your needs
      #!/bin/bash
      #
      # Backup of <your stuff>
      # Improvised by Alik
      #
      
      # create date prefix for archives
      DATE=`date +%Y%m%d`
      
      # save database
      mysqldump -u<username> -p<password> --databases <databasename> >/root/"$DATE"_<databasename>.sql
      tar -cjvf /root/"$DATE"_<databasename>.tar.bz2 /root/"$DATE"_<databasename>.sql
      rm /root/"$DATE"_<databasename>.sql
      
      # save MODx folder
      tar -cjvf /root/"$DATE"_<foldername>.tar.bz2 /path/to/yourMODx/folder/
      
      # set owner and access rights to created archives (if required)
      chown <...........> /root/"$DATE"_*
      chmod <...........> /root/"$DATE"_*
      
      # move archives somewhere (LAN/Samba folder should be a good idea)
      mv /root/"$DATE"_* /some/where