From 3f43d2f768818ed885d0a78a0e9dd936cff75b1c Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Fri, 4 Dec 2020 14:28:18 +0200 Subject: [PATCH] Added new console command for created data backups. --- .gitignore | 3 +++ application/controllers/Console.php | 36 +++++++++++++++++++++++++++++ storage/backups/.htaccess | 1 + storage/backups/index.html | 10 ++++++++ 4 files changed, 50 insertions(+) create mode 100755 storage/backups/.htaccess create mode 100755 storage/backups/index.html 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 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file