0

How to make document-root and database backups to Win10 after I SSH tunnel into my VPS?

For example, after tunneling, how could I download the file backup of both my document-root (/var/www/html) and my database into my Windows desktop?

So far that's what I managed to construct. I especialy wonder what can replace the "download" there:

mysqldump -u root --password --all-databases > /var/www/html/db.sql
zip -r html.zip /var/www/html
DOWNLOAD /var/www/html/db.sql /mnt/c/Users/USER/Desktop/db.sql && scp /var/www/html/html.zip /mnt/c/Users/USER/Desktop/html.zip
rm /var/www/html/db.sql && rm /var/www/html/html.zip
  • Step 1: Update to 1703 – Ramhound Apr 6 '17 at 1:36
2

[Corrected answer]

Once you've completed backing-up and zipping your files via SSH, exit your ssh session and then use scp from Bash:

$ scp <user>@<vps ip address/url>:~/<file> ~/

For example, to copy hello.txt from my Linux VM to my local WSL instance's home folder:

$ scp rich@192.168.1.112:~/hello.txt ~/
  • the ``mv``` is done inside the ssh tunnel so I can't use it to move to my local machine... Regarding cp or scp --- When I use them, /mnt/c is vanished and only a WSL reboot brings it back. Here, I reported this as a possible bug: github.com/Microsoft/BashOnWindows/issues/1868 – JohnDoea Apr 9 '17 at 21:07
  • Added a comment to the bug you filed. Please read. Updating my (original incorrect reply) with corrected, tested answer. – Richard Turner Apr 9 '17 at 21:53
  • Oh wow, so the backup should always be made from WSL and not from the VPS?... That's surprising for me, I got to tell you! But, is there no other way to do this without exiting the VPS, just by means of comfortability? – JohnDoea Apr 9 '17 at 21:59
  • I generally recommend copying data on a remote host from the local host. i.e. copy your VPS' backups to your local machine using scp in the example above. It's generally easier this way around than trying to remote into your VPS and then copy its files back onto your client (which is likely protected by firewalls etc.) – Richard Turner Apr 11 '17 at 1:16
0

Try rsync

enter image description here Also, rm can take multiple arguments, and this line can be combined:

rm db.zip && rm db.sql to $ rm db.zip db.sql

or $ rm db* using the wildcard which the shell will expand to match any pattern after db

or even $ rm db{.zip,.sql} which is another kind of (brace) shell expansion.

  • Hi thanks. You are right regarding to multiple arguments in rm. Anyway, I am not looking for mv because after I SSH tunnel into my VPS, I need a command to download the file from my server --- to my Win10 PC... – JohnDoea Apr 6 '17 at 3:13
  • I see. Didn't realize you were talking about a networked store. I changed the answer. rsync is probably what you're looking for. Check out its man page. It's a great tool. – GH05T Apr 6 '17 at 3:21
  • Thanks. Rsync is indeed powerful and I've heard of it, but to answer the actual question even a small explanation of what you specifically mean I should do with it could not only help in improving and accessing the answer, but could also bring thumb ups (Let us delete comments after an answer edit). – JohnDoea Apr 6 '17 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.