Simple Bash script to make
First of all, if you need a solution that “just works”, you can clone or copy the file from this link: https://github.com/devlionco/bashscripts/blob/master/backup-moodle-full.sh
To use it, just place it in your home directory (or wherever you want on the server) and make it executable with the command:
chmod +x backup-moodle-full.sh
Then launch the script with the only mandatory argument – the directory path, where Moodle’s config.php is located:
./backup-moodle-full.sh /var/www/moodle
The script will create backup_moodle directory near the /var/www/moodle folder and will place
The archive is a file in tar format, that is additionally gzipped.
The archive consists of the full path to moodle installation and keep root code files (Moodle itself), database dump (that is also located in root Moodle directory) and
The log file keeps warnings and messages about the backup process. So if you occur any issues – the best decision is to view the log file.
Below I will try to explain, some the most important things, that script does.
- So,
first script tries to find or create the backup directory. It will be created assibling to the root Moodle directory. - Then,
script looks for DB config options andmoodledata directory location. - The next step is DB dumping. Pay attention, that for now, only MySQL dumping is supported in our script! PostgreSQL dumping will be added in the future script release.
- After this, all the collected data is archived.
- Finally, the cleaning process is launched: DB backup is removed from the root Moodle directory and all backups, that are older than 7 days, are removed from backup directory to save the disk space on the server (the age of files, that will be removed is specified in constant AUTODELETEAFTER
in the beginning of the script).
The last recommendation is to setup
# 4 10 * * * /bin/bash /home/yourusername/backup-wp-advanced.sh /var/www/wp
As an additional option, you can add copying backup data to your own FTP or cloud service (to protect data if the server will destroy). We will add this option in the future script versions.