Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted database backup #34

Open
valentinocossar opened this issue Jul 4, 2016 · 5 comments
Open

Corrupted database backup #34

valentinocossar opened this issue Jul 4, 2016 · 5 comments

Comments

@valentinocossar
Copy link

valentinocossar commented Jul 4, 2016

Hi guys!

I'm experiencing some trouble with backup:remote function. The exported remote .sql.gz file in /tmp folder is perfect, but when download! command downloads the db dump file, locally I find a 15KB file named db_stage_timestamp.sql.gz that's corrupted.

When I try to extract the file with a double click on it, the Mac's Compression Utility returns me a file with a .sql.gz 2.cpgz extension, and if i try to extract the .sql.gz 2.cpgz file, the Mac's Compression Utility returns me a file with a .sql 2.gz extension and so on.

I also tried to extract it with gunzip command, but returns me that error: gunzip: db_stage_timestamp.sql.gz: not in gzip format

I think that the problem isn't the download! command itself, but maybe the Pathname.new() or something else in the backup:remote function, that's because push and pull (that use the downlaod! command) work well without any kind of problem.

Mac OS X version: 10.11.5

Rbenv version: 1.0.0

Ruby version: 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

Here you can find all the gems installed on my Mac:

bigdecimal (1.2.8)
bundler (1.12.5)
capistrano (3.4.1)
capistrano-wpcli (0.1.2)
colorize (0.8.0)
i18n (0.7.0)
io-console (0.4.5)
json (1.8.3)
net-scp (1.2.1)
net-ssh (3.2.0)
psych (2.0.17)
rake (11.2.2)
rdoc (4.2.1)
sshkit (1.7.1)

Any suggestion? Thank you.

@valentinocossar
Copy link
Author

Can someone help me? :(

@sacrom
Copy link
Contributor

sacrom commented Oct 24, 2016

Hi,

I have found today the same problem (on a linux platform). Following the code I have noticed the problem was on (lib/capistrano/tasks/wpdb.rake) at the "download!" call

   desc "Backup the remote database"
      task :remote do
        on roles(:web) do
          within release_path do
            execute :wp, :db, :export, "- |", :gzip, ">", fetch(:wpcli_remote_db_file)
            download! fetch(:wpcli_remote_db_file), Pathname.new(fetch(:wpcli_local_db_backup_dir)).join(fetch(:wpcli_local_db_backup_filename))
            execute :rm, fetch(:wpcli_remote_db_file)
          end
        end
      end

Which caused the Pathname.write() to eventually being called for every 32k of data or less (overwriting and not appending to previous data). I am not a ruby programmer myself and looking at the Pathname documentation I found no clues. So I changed the previous task to use the File object and it just worked:

      desc "Backup the remote database"
      task :remote do
        on roles(:web) do
          within release_path do
            execute :wp, :db, :export, "- |", :gzip, ">", fetch(:wpcli_remote_db_file)
            download! fetch(:wpcli_remote_db_file), File.join(fetch(:wpcli_local_db_backup_dir), fetch(:wpcli_local_db_backup_filename))
            execute :rm, fetch(:wpcli_remote_db_file)
          end
        end
      end

I don't know if this is the right solution, but just in case it helps somebody...

@valentinocossar
Copy link
Author

I've found the (supposed) solution, you've to add .to_s after .join(fetch(:wpcli_local_db_backup_filename)) at the end of this line download! fetch(:wpcli_remote_db_file), Pathname.new(fetch(:wpcli_local_db_backup_dir)).join(fetch(:wpcli_local_db_backup_filename)).

I think this is the right solution, but I'm not sure!

@sacrom
Copy link
Contributor

sacrom commented Oct 25, 2016

Yes that's a correct solution as well. The problem I followed led to the net-scp gem where the download! second argument was checked to honour the :write method (see link).

So if the parameter is:

  • File -> it just works works,
  • String -> A File is created and it works
  • Pathname -> Honours the :write but as far as I can see each write overwrites the previous...

So I guess both solutions led to the same result :-)

Thanks for sharing your solution!

@valentinocossar
Copy link
Author

Thank you for the explanation and for sharing your solution 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants