diff --git a/.gitignore b/.gitignore index f8d1dd06..0d00ef52 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ /assets/js/**/*.min.js /assets/css/**/*.min.css /config.php +/storage/backups/* +!/storage/backups/.htaccess +!/storage/backups/index.html /storage/cache/* !/storage/cache/.htaccess !/storage/cache/index.html diff --git a/application/controllers/Console.php b/application/controllers/Console.php index 03fb5835..a21851db 100644 --- a/application/controllers/Console.php +++ b/application/controllers/Console.php @@ -31,6 +31,8 @@ class Console extends EA_Controller { parent::__construct(); + $this->load->helper('file'); + $this->load->dbutil(); $this->load->library('migration'); $this->load->model('admins_model'); $this->load->model('customers_model'); @@ -156,6 +158,40 @@ class Console extends EA_Controller { $this->output->set_output(PHP_EOL . '⇾ Installation completed, login with "administrator" / "administrator".' . PHP_EOL . PHP_EOL); } + /** + * Create a backup file. + * + * Use this method to backup your Easy!Appointments data. + * + * Usage: + * + * php index.php console backup + * + * php index.php console backup /path/to/backup/folder + * + * @throws Exception + */ + public function backup() + { + $path = isset($GLOBALS['argv'][3]) ? $GLOBALS['argv'][3] : APPPATH . '/../storage/backups'; + + if ( ! file_exists($path)) + { + throw new Exception('The backup path does not exist™: ' . $path); + } + + if ( ! is_writable($path)) + { + throw new Exception('The backup path is not writable: ' . $path); + } + + $contents = $this->dbutil->backup(); + + $filename = 'easyappointments-backup-' . date('Y-m-d-His') . '.gz'; + + write_file(rtrim($path, '/') . '/' . $filename, $contents); + } + /** * Trigger the synchronization of all provider calendars with Google Calendar. * diff --git a/storage/backups/.htaccess b/storage/backups/.htaccess new file mode 100755 index 00000000..3418e55a --- /dev/null +++ b/storage/backups/.htaccess @@ -0,0 +1 @@ +deny from all \ No newline at end of file diff --git a/storage/backups/index.html b/storage/backups/index.html new file mode 100755 index 00000000..c942a79c --- /dev/null +++ b/storage/backups/index.html @@ -0,0 +1,10 @@ + +
+Directory access is forbidden.
+ + + \ No newline at end of file