1

I am new to Ubuntu but I have to do a small script which backups all my files on my server to my local computer. I made a script on my server called backupscript and put the following command

zip -r Backupfile /home/ubuntu
sudo scp -P 22 /home/ubuntu/Backupfile.zip user@ipaddress:/home/user

I save it and execute this script from terminal ./backupscript

But then I get a message ssh: connection to host ipaddress port 22: connection lost.

I opened port 22 in my host computer using this sudo ufw allow 22

but still unable to scp the file from my server to host computer.

user696518
  • 11
  • 1
  • can you modify your script to include -v immediately after scp, rerun the command and edit your question ti include the results. This should give some diagnostic information that may help solve the issue – Nick Sillito Jun 04 '17 at 07:32
  • Also, I am not sure why you have sudo at the start of the scp line. Whilst I dont think that its a problem, it would help diagnostics if you could rerun with out the sudo command – Nick Sillito Jun 04 '17 at 07:36
  • firstly, just try to ssh into your box – davidbaumann Jun 04 '17 at 07:47
  • If in front of your local network has a router you must forward the router's port 22 to your local computer. Check this answer for more details. – pa4080 Jun 04 '17 at 09:10
  • 1
    Maybe the better and easiest way is to copy files from the local machine itself. Something as: sudo scp -P 22 user@remote-server:/home/ubuntu/Backupfile.zip /home/user. So you can create cronjob on the remote server that will create the backup, and cronjob on the local machine that will download the backup. – pa4080 Jun 04 '17 at 09:10
  • 2
    btw -- rsync is often a better option than scp. If you're doing a backup, scp will copy everything, every time. rsync will just send the changes and therefore saves time (esp if youre on a slow connection) – Nick Sillito Jun 04 '17 at 10:49

0 Answers0