CpanelInc / backup-transport-dropbox

cPanel Custom Backup Transport for Dropbox
Apache License 2.0
15 stars 7 forks source link

TECH-609: validation error and does not transfer account backup to dropbox #3

Closed erojiraiya closed 6 years ago

erojiraiya commented 6 years ago

I am trying to set dropbox as custom backup destination following below cpanel blog. The connection is working, but the backup files are not being transferred to DropBox. And when I press validate to custom backup destination it gives following error .

https://blog.cpanel.com/cpanel-whm-custom-backup-transport-example-dropbox/

Error: Validation for transport “dropbox” failed: Could not list files in 
destination: Executed /usr/local/bin/backup_transport_dropbox.pl ls / 
remotehost remoteuser : 2018-08-26T15:54:21 [WebService::Dropbox] [ERROR] 
https://api.dropboxapi.com/2/files/list_folder {"path":"/"} -> [400] Error in 
call to API function "files/list_folder": request body: path: Specify the root 
folder as an empty string rather than as "/". at 
/usr/local/share/perl5/WebService/Dropbox.pm line 184.

I am new to dropbox api and have no idea of perl.

cPWilliamL commented 6 years ago

Hi,

This may be a bug. For the time being, are you able to work around the issue by specifying a directory in dropbox and the transport?

Thanks,

erojiraiya commented 6 years ago

Hi,

Thank You for your reply. I could not find where to specify a directory. I created dropbox app with both app directory access and with full access. In both cases, out of WHM backup, system directory gets transferred to dropbox but the accounts directory is empty.

Could it be due to large size full cpanel backups ? I do not think it is the case.

Also the validation error I mentioned, I could not get it fix too.

I believe this is a fully tested workaround you developed for cpanel and dropbox. If this works, lots of people will be benefited by your nice work. I hope this works soon enough to thank you with the sincerest great fullness of your contribution.

Thanks

erojiraiya commented 6 years ago

While I was trying to figure out to set the path, I found following script and manually set the path and the validation changed to different other errors. sub convert_path {

my ($path) = @_;

return '' if $path eq '/';
$path = $1 if ( $path  =~ s|(.+)/\z|| );

if ( $path =~ m|^/| ) {
    return $path;
}
else {
    return File::Spec->catdir( $local_dir, $path );
}

}

I tested the application on dedicated cPanel server and there was no such validation error. Also, while installing WebService::DropBox with cpan on dedicated server, there was no additional prompt confirmation show for packages only for test that are described on the blog .

Could it be that the mechanism of WebService::DropBox be different for Dedicated and VPS ?

cPWilliamL commented 6 years ago

[400] Error in call to API function "files/list_folder": request body: path: Specify the root folder as an empty string rather than as "/"

This should now be corrected in the 'development' branch. This issue has appeared as a result of new validation methods for backup transports. I have filed an internal case for the backup transport path validation inconsistencies under CPANEL-22692.

Regardless, I pushed a fix to the development branch in the following commits(after further testing, I will push it to master): 885eabe2a8ea18eb497addacce6ee84594c32b7b 519bda2ca0d0eb77ea9293d087a011e1ab99720e

commit 885eabe2a8ea18eb497addacce6ee84594c32b7b (HEAD -> development, origin/development)
Author: red <devnull@red.edge-cent7.com>
Date:   Wed Sep 5 15:07:44 2018 -0500

    add comments to regex changes in convert_path

diff --git a/backup_transport_dropbox.pl b/backup_transport_dropbox.pl
index d386f31..cc2f0ec 100755
--- a/backup_transport_dropbox.pl
+++ b/backup_transport_dropbox.pl
@@ -69,7 +69,9 @@ sub usage {
 sub convert_path {
     my ($path) = @_;

+    # return empty string if path is slash or empty
     return '' if ( $path =~ s@^(/|)\z@@ );
+    # strip trailing slash
     $path = $1 if ( $path  =~ s@(.+)/\z@@ );

     if ( $path =~ m|^/| ) {

commit 519bda2ca0d0eb77ea9293d087a011e1ab99720e (origin/development-TECH-609, development-TECH-609)
Author: red <devnull@red.edge-cent7.com>
Date:   Wed Sep 5 14:43:33 2018 -0500

    fix TECH-609: adjust convert_path regex for empty path

diff --git a/backup_transport_dropbox.pl b/backup_transport_dropbox.pl
index 9acc450..d386f31 100755
--- a/backup_transport_dropbox.pl
+++ b/backup_transport_dropbox.pl
@@ -69,8 +69,8 @@ sub usage {
 sub convert_path {
     my ($path) = @_;

-    return '' if $path eq '/';
-    $path = $1 if ( $path  =~ s|(.+)/\z|| );
+    return '' if ( $path =~ s@^(/|)\z@@ );
+    $path = $1 if ( $path  =~ s@(.+)/\z@@ );

     if ( $path =~ m|^/| ) {
         return $path;
cPWilliamL commented 6 years ago

Thank you again for your report and patience @erojiraiya. Please let me know if you have issues with the development branch. I will close this after giving you some time to review and once the changes have been pushed to master.

erojiraiya commented 6 years ago

Hi @cPWilliamL

Thank you for the fix. The validation and backup transfer to Dropbox is working perfectly. Both system and accounts backup is now being transferred to DropBox.

Your work is awesome. Thank you for you great contribution.

Cheers 👍