EideardVMR / unraid-easybackup

Snapshot for virtual machines and backups for them, as well as for Docker
GNU General Public License v3.0
8 stars 1 forks source link

File Mounts in Docker causes Backup to throw Error: "Failed to open directory: Not a directory" #13

Open GraphicHealer opened 3 months ago

GraphicHealer commented 3 months ago

Hello!

I am using this plugin, and I have WikiJS (A Wiki webpage engine) loaded as a container. One of it's docker mount points is a File, Not a directory, as seen here: image (The favicon.ico file)

When I have this set, EasyBackup keeps throwing an error when the backup is run, as shown here:

2024-07-17 02:47:33 DEBUG    Container: Start Backup "wikijs"
2024-07-17 02:47:33 DEBUG    Add job in category "container" with id "de2b9a0030d0c2073b3f1a368909398e43e920f8ebb06c89409821199614b412"
2024-07-17 02:47:33 DEBUG    Save jobfile: /boot/config/plugins/easybackup/jobs.json
2024-07-17 02:47:33 DEBUG    Container: Stop Container "wikijs"
2024-07-17 02:47:36 INFO     
2024-07-17 02:47:36 DEBUG    Container: Load informations of "wikijs"
2024-07-17 02:47:36 DEBUG    Container: Informations of "wikijs" found
2024-07-17 02:47:37 INFO     Container: Backup 8 files of "/mnt/user/appdata/wikijs/favicons"
2024-07-17 02:47:37 INFO     Container: Backup 4 files of "/mnt/user/appdata/wikijs/config"
2024-07-17 02:47:39 INFO     Container: Backup 1113 files of "/mnt/user/wikijs"
2024-07-17 02:47:39 WARNING  scandir(/mnt/user/appdata/wikijs/favicon.ico): Failed to open directory: Not a directory
File: /usr/local/emhttp/plugins/easybackup/includes/functions.php
Line: 267
2024-07-17 02:47:39 WARNING  Trace:
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/functions.php:267
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/Docker.class.php:227
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/job.php:47
2024-07-17 02:47:39 WARNING  scandir(): (errno 20): Not a directory
File: /usr/local/emhttp/plugins/easybackup/includes/functions.php
Line: 267
2024-07-17 02:47:39 WARNING  Trace:
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/functions.php:267
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/Docker.class.php:227
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/job.php:47
2024-07-17 02:47:39 WARNING  foreach() argument must be of type array|object, bool given
File: /usr/local/emhttp/plugins/easybackup/includes/functions.php
Line: 270
2024-07-17 02:47:39 WARNING  Trace:
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/Docker.class.php:227
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/job.php:47
2024-07-17 02:47:39 INFO     Container: Backup 0 files of "/mnt/user/appdata/wikijs/favicon.ico"
2024-07-17 02:47:39 INFO     VM: determine Backuppath: /mnt/user/backup_internal/appdata/wikijs/2024-07-17_02.47
2024-07-17 02:47:39 INFO     Container: Backup with Zip Compression to: /mnt/user/backup_internal/appdata/wikijs/2024-07-17_02.47.zip
2024-07-17 02:49:27 DEBUG    Remove job from category "container" with id "de2b9a0030d0c2073b3f1a368909398e43e920f8ebb06c89409821199614b412"
2024-07-17 02:49:27 DEBUG    Save jobfile: /boot/config/plugins/easybackup/jobs.json
2024-07-17 02:49:27 DEBUG    Container: Start Container "wikijs"
2024-07-17 02:49:28 INFO     
2024-07-17 02:49:28 DEBUG    Container: Load informations of "wikijs"
2024-07-17 02:49:28 DEBUG    Container: Informations of "wikijs" found

The error states WARNING scandir(/mnt/user/appdata/wikijs/favicon.ico): Failed to open directory: Not a directory which means that EasyBackup at the moment cannot differentiate between a folder mount, and a file mount. It just assumes all are folders, and this will cause it to fail.

I have previously used file-type mounts, and it would be necessary to have them backed up as well.

Looking at your code, it looks like you could change the scandirRecursive function to something like this:

function scandirRecursive($dir, &$results = array()) {

    // This if statement I added will either add $dir as a file directly, or run 'scandir()' depending on the type.
    if (is_file($dir)) {
      $files[] = $dir;
    } else {
      $files = scandir($dir);
    }

    //Log::LogInfo("scandir Start: " . $dir);

    foreach ($files as $value) {
        $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
        if (is_file($path)) {
            //Log::LogInfo("scandir File: " . $path);
            $results[] = $path;
        } else if (is_dir($path) && $value != "." && $value != "..") {
            //Log::LogInfo("scandir Dir: " . $path);
            scandirRecursive($path, $results);
            //$results[] = $path;
        }
    }

    return $results;
}

Hopefully this helps!

- G

GraphicHealer commented 3 months ago

Actually, I'll open a quick pull request. Give me a couple minutes.

EideardVMR commented 3 months ago

Hi, unfortunately I'm currently on vacation and can't help at the moment. But I'll look into it next week. I think it's a minor issue that can be fixed quickly.

Am 17. Juli 2024 16:29:22 MESZ schrieb GraphicHealer @.***>:

Hello!

I am using this plugin, and I have WikiJS (A Wiki webpage engine) loaded as a container. One of it's docker mount points is a File, Not a directory, as seen here: image (The favicon.ico file)

When I have this set, EasyBackup keeps throwing an error when the backup is run, as shown here:

2024-07-17 02:47:33 DEBUG    Container: Start Backup "wikijs"
2024-07-17 02:47:33 DEBUG    Add job in category "container" with id "de2b9a0030d0c2073b3f1a368909398e43e920f8ebb06c89409821199614b412"
2024-07-17 02:47:33 DEBUG    Save jobfile: /boot/config/plugins/easybackup/jobs.json
2024-07-17 02:47:33 DEBUG    Container: Stop Container "wikijs"
2024-07-17 02:47:36 INFO     
2024-07-17 02:47:36 DEBUG    Container: Load informations of "wikijs"
2024-07-17 02:47:36 DEBUG    Container: Informations of "wikijs" found
2024-07-17 02:47:37 INFO     Container: Backup 8 files of "/mnt/user/appdata/wikijs/favicons"
2024-07-17 02:47:37 INFO     Container: Backup 4 files of "/mnt/user/appdata/wikijs/config"
2024-07-17 02:47:39 INFO     Container: Backup 1113 files of "/mnt/user/wikijs"
2024-07-17 02:47:39 WARNING  scandir(/mnt/user/appdata/wikijs/favicon.ico): Failed to open directory: Not a directory
File: /usr/local/emhttp/plugins/easybackup/includes/functions.php
Line: 267
2024-07-17 02:47:39 WARNING  Trace:
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/functions.php:267
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/Docker.class.php:227
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/job.php:47
2024-07-17 02:47:39 WARNING  scandir(): (errno 20): Not a directory
File: /usr/local/emhttp/plugins/easybackup/includes/functions.php
Line: 267
2024-07-17 02:47:39 WARNING  Trace:
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/functions.php:267
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/Docker.class.php:227
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/job.php:47
2024-07-17 02:47:39 WARNING  foreach() argument must be of type array|object, bool given
File: /usr/local/emhttp/plugins/easybackup/includes/functions.php
Line: 270
2024-07-17 02:47:39 WARNING  Trace:
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/includes/Docker.class.php:227
2024-07-17 02:47:39 WARNING  /usr/local/emhttp/plugins/easybackup/job.php:47
2024-07-17 02:47:39 INFO     Container: Backup 0 files of "/mnt/user/appdata/wikijs/favicon.ico"
2024-07-17 02:47:39 INFO     VM: determine Backuppath: /mnt/user/backup_internal/appdata/wikijs/2024-07-17_02.47
2024-07-17 02:47:39 INFO     Container: Backup with Zip Compression to: /mnt/user/backup_internal/appdata/wikijs/2024-07-17_02.47.zip
2024-07-17 02:49:27 DEBUG    Remove job from category "container" with id "de2b9a0030d0c2073b3f1a368909398e43e920f8ebb06c89409821199614b412"
2024-07-17 02:49:27 DEBUG    Save jobfile: /boot/config/plugins/easybackup/jobs.json
2024-07-17 02:49:27 DEBUG    Container: Start Container "wikijs"
2024-07-17 02:49:28 INFO     
2024-07-17 02:49:28 DEBUG    Container: Load informations of "wikijs"
2024-07-17 02:49:28 DEBUG    Container: Informations of "wikijs" found

The error states WARNING scandir(/mnt/user/appdata/wikijs/favicon.ico): Failed to open directory: Not a directory which means that EasyBackup at the moment cannot differentiate between a folder mount, and a file mount. It just assumes all are folders, and this will cause it to fail.

I have previously used file-type mounts, and it would be necessary to have them backed up as well.

Looking at your code, it looks like you could change the scandirRecursive function to something like this:

function scandirRecursive($dir, &$results = array()) {

   // This if statement I added will either add $dir as a file directly, or run 'scandir()' depending on the type.
   if (is_file($dir)) {
     $files[] = $dir;
   } else {
     $files = scandir($dir);
   }

   //Log::LogInfo("scandir Start: " . $dir);

   foreach ($files as $value) {
       $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
       if (is_file($path)) {
           //Log::LogInfo("scandir File: " . $path);
           $results[] = $path;
       } else if (is_dir($path) && $value != "." && $value != "..") {
           //Log::LogInfo("scandir Dir: " . $path);
           scandirRecursive($path, $results);
           //$results[] = $path;
       }
   }

   return $results;
}

Hopefully this helps!

- G

-- Reply to this email directly or view it on GitHub: https://github.com/EideardVMR/unraid-easybackup/issues/13 You are receiving this because you are subscribed to this thread.

Message ID: @.***> -- Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

GraphicHealer commented 3 months ago

I have submitted a pull request with a possible fix. You can look at it when you get the time. Thanks!

GraphicHealer commented 2 months ago

Any updates on the pull requests?

EideardVMR commented 2 months ago

Hi, I haven't really had time to work on the project yet. I'm sure I'll get back to it in the fall or winter at the latest. Possibly even sooner. But I will take your points into consideration.