diff --git a/README.md b/README.md index 292370e..903bade 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,10 @@ Simple Backup Utility is a PHP script that allows you to create and manage backu ## Features - **Backup Creation**: Easily create backups of specific folders. +- **Multiple Folder Backup**: Select and backup multiple folders simultaneously. - **Backup Deletion**: Remove existing backup folders. - **User-Friendly Interface**: Intuitive web interface for straightforward operation. +- **Easy Update**: Built-in update feature for seamless updates to the latest version. ## Requirements @@ -20,7 +22,7 @@ Simple Backup Utility is a PHP script that allows you to create and manage backu ## Installation -1. Clone the repository or download the ZIP file. +1. Clone the repository or download the [latest release](https://github.com/dynamiccookies/Simple-Backup-Utility/releases/latest). 2. Place the script (`index.php`) in the directory where you want to manage backups. 3. Ensure the directory has appropriate permissions for creating and deleting files and folders. @@ -29,17 +31,24 @@ Simple Backup Utility is a PHP script that allows you to create and manage backu ### Creating a Backup 1. Access the script via a web browser after installation. -2. Enter a name for your backup in the "Backup Name" field. -3. Click the "Backup" button for the environment folder you want to backup. +2. Enter a name for your backup(s) in the "Backup Name" field. +3. Place a checkmark next to each of the folders you'd like to backup. +4. Click the "Backup Selected Folders" button. ### Deleting a Backup 1. Click the trash icon next to the Existing Backups entry. +### Updating to Latest Version + +Only available if you see the New Version Available message in the bottom right corner of the screen. + +1. Click the (Update Now) link in the New Version Available message. +2. When the page reloads, the new version number should be shown. ## Folder Structure -The Simple Backup Utility expects the following directory structure: +The Simple Backup Utility expects the following parent/child directory structure: - Project Directory - prod - staging @@ -56,7 +65,7 @@ The script displays all of its parent directory's sibling folders. In this examp The backup process names the selected directory using the format `_` based on the selected directory to backup. -**Note:** The names of all files and folders are arbitrary and can be customized as needed. +**Note:** The names of all files and folders are arbitrary and can be customized as needed, including `index.php`. ## License @@ -65,4 +74,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file ## Support -For any issues, questions, or feature requests, please [open an issue](https://github.com/dynamiccookies/Simple-Backup-Utility/issues). +For any issues, questions, or feature requests, please [open an issue](https://github.com/dynamiccookies/Simple-Backup-Utility/issues/new). diff --git a/index.php b/index.php index e1b3f27..5e5a433 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ // * Define constant for the current version // **************************************************************************************** date_default_timezone_set('America/Chicago'); -define('CURRENT_VERSION', 'v0.2.1'); +define('CURRENT_VERSION', 'v0.3.0'); // **************************************************************************************** // * Define variables for API URL, directories, and other data @@ -12,6 +12,7 @@ $apiUrl = 'https://api.github.com/repos/dynamiccookies/Simple-Backup-Utility/releases'; $current_dir = getcwd(); // Get current directory $folders = get_sibling_folders($current_dir); // Get sibling folder names excluding current directory +$green = '#28a745'; $latestVersion = get_latest_release_tag($apiUrl); $message = ''; $messageColor = "#dc3545"; @@ -42,17 +43,20 @@ function backup_folder($source, $destination) { return 0; } @mkdir($destination, 0777, true); + $count = 1; $files = array_diff(scandir($source), array('.', '..')); + foreach ($files as $file) { $src = "$source/$file"; $dst = "$destination/$file"; if (is_dir($src)) { - backup_folder($src, $dst); + $count += backup_folder($src, $dst); } else { copy($src, $dst); + $count ++; } } - return count($files); + return $count; } /** @@ -66,7 +70,7 @@ function compare_versions($currentVersion, $latestVersion) { // Remove 'v' prefix for comparison $currentVersionClean = ltrim($currentVersion, 'v'); $latestVersionClean = ltrim($latestVersion, 'v'); - + // Compare versions and switch on the result switch (version_compare($currentVersionClean, $latestVersionClean)) { case -1: @@ -170,12 +174,12 @@ function get_sibling_folders($dir) { if (isset($_POST['delete'])) { // Construct the path to the folder to delete $folder_to_delete = $current_dir . '/' . $_POST['delete']; - + // Attempt to delete the folder if (delete_backup_folder($folder_to_delete)) { // Set success message if deletion is successful $message = "The folder '{$_POST['delete']}' has been deleted."; - $messageColor = "#28a745"; // Green color for success message + $messageColor = $green; } else { // Set error message if deletion fails $message = "Failed to delete the folder '{$_POST['delete']}'."; @@ -195,39 +199,36 @@ function get_sibling_folders($dir) { // Check if a backup action is requested } elseif (isset($_POST['backup'])) { - - // Check if a valid backup folder is selected - if (in_array($_POST['backup'], $folders)) { - // Define the source path for backup - $source = "../{$_POST['backup']}"; - } else { - // Set error message for invalid backup folder selection - $message = 'Invalid backup folder selected.'; - } - // Proceed if no error message is set - if (empty($message)) { + // Check if any folders are selected for backup + if (!isset($_POST['backup_folders']) || empty($_POST['backup_folders'])) { + $message = 'No folders selected for backup.'; + } else { + // Loop through selected folders and initiate backup + foreach ($_POST['backup_folders'] as $selected_folder) { + // Define the source path for backup + $source = "../" . $selected_folder; - // Define the destination folder name and path - $folder_name = $_POST['backup'] . '_' . preg_replace('/\s+/', '-', trim($_POST['folder_name'])); - $destination = "../" . basename($current_dir) . "/" . $folder_name; + // Define the destination folder name and path + $folder_name = $selected_folder . '_' . preg_replace('/\s+/', '-', trim($_POST['folder_name'])); - // Check if the destination folder already exists - if (is_dir($destination)) { - // Set error message if the destination folder already exists - $message = "The folder '$folder_name' already exists. Backup cannot be completed."; - } else { - // Perform the backup operation - $file_count = backup_folder($source, $destination); - - // Check if files are successfully backed up - if ($file_count > 0) { - // Set success message if backup operation is successful - $message = "The folder '$folder_name' has been created with $file_count files."; - $messageColor = "#28a745"; // Green color for success message + // Check if the destination folder already exists + if (is_dir($folder_name)) { + // Set error message if the destination folder already exists + $message .= "The folder '$folder_name' already exists. Backup cannot be completed.
"; } else { - // Set error message if backup operation fails - $message = "Failed to create the folder '$folder_name'."; + // Perform the backup operation + $file_count = backup_folder($source, $folder_name); + + // Check if files are successfully backed up + if ($file_count > 0) { + // Set success message if backup operation is successful + $message .= "The folder '$folder_name' has been created with " . ($file_count - 1) . " files/folders.
"; + $messageColor = $green; + } else { + // Set error message if backup operation fails + $message .= "ERROR: '$folder_name' is not a valid directory!
"; + } } } } @@ -284,7 +285,7 @@ function get_sibling_folders($dir) { gap: 10px; margin-bottom: 20px; } - .button-container button, .message { + button.backup, .message { box-shadow: 0 8px 8px 1px rgba(0, 0, 0, .2); font-weight: bold; } @@ -335,6 +336,16 @@ function get_sibling_folders($dir) { table th:nth-child(3), table td:nth-child(3) { width: 10%; } + .checkbox-columns { + display: flex; + gap: 20px; + text-align: left; + } + .checkbox-column label { + display: block; + white-space: nowrap; + margin-bottom: 5px; + } .divider { border-top: 1px solid #fff; margin: 20px 0; @@ -372,6 +383,7 @@ function confirmDelete(folderName, formId) { } } + // Function to trigger update from GitHub repository's latest release function triggerUpdate() { const form = document.createElement('form'); form.method = 'post'; @@ -395,23 +407,47 @@ function triggerUpdate() {
-
- - - +
"; + for ($j = 0; $j < $folders_per_column; $j++) { + $folder_index = $j * $columns + $i; + if ($folder_index < $total_folders) { + $folder = $folders[$folder_index]; + echo "\n\t\t\t\t\t" . '
'; + } + } + echo "\n\t\t\t\t
"; + } + ?> +
+
- -
- -
- + $message"; ?>
+ No Backups Found'; + } else { + ?> +

Existing Backups

@@ -422,27 +458,26 @@ function triggerUpdate() { Delete $folder): ?> - - - - - -
- - -
- - + foreach ($backup_folders as $index => $folder): + ?> + + + +
+ + +
+ + + + - +
-