Run manual backup task from url, something like cron.php.

Problem

Currently manual backup can be done only via the GUI thus this action can't be scriptable (included in more complex processes, like auto upgrade/migration, etc. ).

Use case - Manually backup site before upgrade on shared hosting

Dev want to upgrade client site. The site is on shared hosting. On most (at least on all low cost) shared hosting solutions there is no SSH access (only FTP) and the MySql server is accessible locally only therefore Dev must use tool on the server to make the DB backup. In our case Dev goes to backup_migrate, backup manually (via GUI), retrieves site files via FTP (if destination is files folder) and then upgrades.

In version X of backup_migrate the backup task can be launched via url. The Dev makes a backup script which includes :
wget -O - -q -t 1 http://www.example.com/backup/manual/default
and all the process is automated.

Implementation

There are two major problems security and error handling, the rest is backup_migrate_perform_backup($settings).

1. Security. The access to the backup url must be protected.

Here some ideas how this problem can be resolved #52910: Restrict access to cron. The main idea is to add randomly generated key to the url http://www.example.com/backup/manual/default?backup_key=... . The full url will be available in the GUI and the key can be regenerated if compromised. The key stored in variable_set/get and initially generated at install.

2. Error handling. There must be mechanism to report if backup failed. Simple approach can be :

The back up script (http://www.example.com/backup/manual/default?backup_key=...)


// backup process

// at the end  
$backup_ok = TRUE;

if ( $backup_ok ) {
  print 0;
} else {
  print 1;
}

And then in bash (or whatever the script) :

#!/bin/bash
BACKUP_OK=$(wget -O - -q -t 1 http://www.example.com/backup/manual/default?backup_key=...)
if [[ $BACKUP_OK != 0 ]]; then
  echo "manual backup failed"
  # do stuff
fi
echo "manual backup ok"
# do stuff

Am I the only who needs this ? Suggestions, ideas, alternative approaches are welcome.

- dankh

Comments

ronan’s picture

Status: Active » Closed (won't fix)

Closing this in to clean up old tickets. Please reopen if it's still applicable.

daigo75’s picture

I have exactly the same need. Subscribing.

daigo75’s picture

I ended up creating a super-tiny module which allows to download a backup by simply opening a URL. It doesn't provide any strong security mechanism, just simple Drupal permissions, and just returns HTTP 500 in case of error, but it does the job for what I need (I only use it in my local development environment).

If still interested, I can attach it to the thread.