I can do every single step:
1, compress file using tar
2, copy to remote machine using scp
3, login remote machine using ssh, need password
4, uncompress the file
but, I want to write a single script to do the work, anyone suggestion?
1 Answer
Why don't you use rsync
to do that? From the computer were you want to get the file
rsync [email protected]:/home/myuser/mydir/myfile myfile
will move the file over the two computers, taking care of the transportation. You can even pass recursively (-r
) if you want to sync the whole directory.
Regarding compressing the data, you can obtain it via -z
option, but keep in mind that if your connection is fast and your CPU is slow (mobile devices) you will have better performances just transferring the data without compressing them.
--
Following the comment below, I suggested to look into fabric (http://www.fabfile.org/), which will give you the ability to operate on a server by remote.
so for example as a template you could:
```
from fabric.api import run
def kill_and_replace():
run('killall myserverprocess')
run('cp mynewfile myoldfile')
```
-
I'm sorry, I didn't said clearly, Acutally, it's not just sync files, I need login to remote machine to kill the server program, and then replace the files it needed, and then restart it, so it will be updated– Liu HaoFeb 1, 2016 at 8:52
tar
does not compress. It just puts multiple files together into one single file, but without any compression. You use e.g.gzip
orbzip
to compress atar
file. Thetar
command is still necessary though, because those compression algorithms can only operate on single files.-z
flag to compress