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.

  • 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 Jun 4, 2017 at 7: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 Jun 4, 2017 at 7:36
  • firstly, just try to ssh into your box Jun 4, 2017 at 7:47
  • 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 4, 2017 at 9: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) Jun 4, 2017 at 10:49


You must log in to answer this question.

Browse other questions tagged .