by Ken Task.
Ok, now we know it's a Xbuntu (Linux) machine. What I'm sharing with you does work on a CentOS flavored linux box. I don't have a Xbuntu machine, but this sort of scripting should work on an Xbuntu machine as well. What's the diff? Primarily paths ... where one finds things in Xbuntu as opposed to CentOS (for which the info has been provided).
** All of what has been shared is command line ONLY! ** Cannot use the browser to execute. Must login to the machine via terminal session (ssh) and type the commands as root user (or in your case, you might need to add 'sudo' in front of all commands). Sudo is 'substitute user' ... allows a regular user account that is in sudo users group to be able to use root commands without having to be the root user all the time.
touch /usr/bin/moodledbbackup
That created a blank file at /usr/bin/ called 'moodledbbackup'.
Then, you entered into the above file the following:
cd /var/www/html/moodle/;
php admin/cli/maintenance.php --enable;
mysqldump -u moodleuser -p'pw' moodle > /var/www/moodlebu/mdldb-$(date +%Y%m%d%-H%M%S).sql
ls -l /moodledbbackup/*.sql;
php admin/cli/maintenance.php --disable;
First ... is the moodle code located in /var/www/html/
If it is one can see a config.php file there ... ls config.php at that location will list it if the file is there.
The php commands provide the path relative to location ... in /var/www/html/moodle/
one can see an admin directory and contained therein a cli directory.
The directory in your script: /var/www/moodlebu *MUST* exist. The script will not create
it for you.
The ls -l command is to show the .sql file.
It needs to be adjusted to show the full path to where the .sql file was saved.
In the mysqldump line that is /var/www/moodlebu/
so the ls -l command *must* be
ls -l /var/www/moodlebu/*.sql
After you've made the corrections, you must make the 'moodledbbackup' file executable.
in /usr/bin/
chmod u+x moodledbbackup
chmod ... changes/modifies a files permissions and settings
u means user +x means add to the file the ability to execute it's contents.
ls -l moodledbbackup
would show/reflect your changes to persmissons:
*example is from a server that has several backup type scripts for versions of Moodle:
-rwxr----- 1 root root 191 Jan 22 2014 backupmoodle25
-rwxr----- 1 root root 191 Jan 22 2014 backupmoodle26
-rwxr----- 1 root root 191 Feb 18 2015 backupmoodle27
-rwxr----- 1 root root 191 Feb 18 2015 backupmoodle28
-rwxr----- 1 root root 345 Jan 17 2016 backupmoodle29
-rwxr----- 1 root root 267 Jan 3 2016 backupmoodle30
-rwxr----- 1 root root 368 Jun 8 07:55 backupmoodle31
All belong to root user and are in root group
The first -rwx in file attributes means it is readable, writable, and executable
to the root user.
the second rw- indicates any other user that is part of the root group can read and write
but cannot execute the script.
The last set of there --- means all other users .... who have no permissions to read the file, nor write to the file nor execute the file.
Now because the moodledbbackup file is in /usr/bin/ one can execute it from any location.
So right after you login via terminal, at the prompt type: moodledbbackup [ENTER]
*** Since you are on Xbuntu, one might have to use "sudo" then a space before the command. You will be prompted for your password then.
'spirit of sharing', Ken