rsync help

Associate
Joined
16 Jan 2006
Posts
970
Location
North Wales
Hi

am looking to backup a web server online to a home server at home using rsync (data only)

i have run the following command

rsync -v -e 'ssh -p 2222 root@"IP":/root/home/clickit/*' '/home/backup/' (change the IP to the ip of my server)

i get the following back, i was waiting for a prompt to enter the server password really.


building file list ... done
drwx------ 98 2019/02/12 16:40:12 .
-rw------- 79 2019/02/12 16:40:12 .bash_history
-rw-r--r-- 18 2018/10/30 17:07:12 .bash_logout
-rw-r--r-- 193 2018/10/30 17:07:12 .bash_profile
-rw-r--r-- 231 2018/10/30 17:07:12 .bashrc
drwxrwxr-x 6 2019/02/12 16:38:04 sheldon

sent 140 bytes received 371 bytes 1,022.00 bytes/sec
total size is 521 speedup is 1.02

All it has done on the backup rsync server is created a folder called sheldon - sheldon is the host name of the web server.

Any idea's what i am doing wrong?

Thank You
 
Associate
Joined
13 Jun 2007
Posts
1,316
Location
London
Looks like you need to add -r option to recurse through folders.

I like to use -a option for archiving when using rsync for backups. It includes the following:

Code:
-r, --recursive recurse into directories

-l, --links copy symlinks as symlinks

-p, --perms preserve permissions

-t, --times preserve modification times

-g, --group preserve group

-o, --owner preserve owner (super-user only)

-D same as --devices --specials

--devices preserve device files (super-user only)

--specials preserve special files
 
Soldato
Joined
3 Oct 2013
Posts
3,602
I use

Code:
rsync -r -t -v -P -e ssh /source user@server/destination

This is what I use to do a backup from my desktop to server. I use ssh with a key file as saves messing with passwords for this particular task.
 
Associate
OP
Joined
16 Jan 2006
Posts
970
Location
North Wales
rsync -zavP -e 'ssh -p 2222' root@IP:/root/home/clickit/ /home/backup/

Sorry for the late reply only just got back on to this project.

That worked perfectly thank you. what is the zavp -e for? new to rsync sorry


I use

Code:
rsync -r -t -v -P -e ssh /source user@server/destination

This is what I use to do a backup from my desktop to server. I use ssh with a key file as saves messing with passwords for this particular task.


Do you know where i can learn about key files?
 
Associate
Joined
16 May 2008
Posts
2,484
Location
Bristol
That worked perfectly thank you. what is the zavp -e for? new to rsync sorry

-z, compress file data during the transfer
-a, archive mode; equals -rlptgoD (no -H,-A,-X)
-v, increase verbosity
-P, show progress and keep partially transferred files if interrupted

`man rsync` will give you loads more details
 
Associate
OP
Joined
16 Jan 2006
Posts
970
Location
North Wales
Sorry to come back to this after such a while but i have 1 more question if anyone can help -

rsync -zavP -e 'ssh -p 2222' root@IP:/root/home/ /home/backup/

When i do this it asks for the root password of the server. I want to turn this in to a cron job but it will stop on the password screen wouldnt it? i want to set up a cron for 3 times aday but how can i get around it asking for the root password? do i add something to the command?
 
Soldato
Joined
5 Nov 2011
Posts
5,356
Location
Derbyshire
Sorry to come back to this after such a while but i have 1 more question if anyone can help -

rsync -zavP -e 'ssh -p 2222' root@IP:/root/home/ /home/backup/

When i do this it asks for the root password of the server. I want to turn this in to a cron job but it will stop on the password screen wouldnt it? i want to set up a cron for 3 times aday but how can i get around it asking for the root password? do i add something to the command?

If you set the SSH keys up you won't be asked for a password.
 

SMN

SMN

Soldato
Joined
2 Nov 2008
Posts
2,502
Location
The ether
What Steveocee said :D

Also, Can I make a point of using a user rather than root !

I have to reiterate this, x1000.

Few things to do:
1. On all boxes, set 'PermitRootLogin no'.

2. Use keys to login, not passwords: From the box you want to login FROM, run 'ssh-copy-id bilbo@server -p 2222' and login using the password. After this, you can simply 'ssh bilbo@server -p 2222' and you are in. Then you can go ahead and disable password login entirely, or not if you dont feel comfortable.

3. Use SSH config to your advantage: If you are using rsync and the like, non-standard ports are generally a faff. I always use SSH config to bypass this; edit ~/.ssh/config on the box you are SSH'ing FROM and add something like:
Code:
Host server
    HostName 192.168.0.254
    Port 2222
    User bilbo

Afterwards, you can simply 'ssh server' and you are in (if you did my step 2, above).

That then potentially makes your rsync command a lot simpler too, as you enter less params.

HTH.
 
Last edited:
Soldato
Joined
10 Oct 2005
Posts
8,706
Location
Nottingham
I agree completely with not using the root user to connect remotely, but if the OP does make this change they should remember to check that the user which they are connecting as does have the access required to be able to transverse directories and read the files which are to be synced. It may have worked as root previously but random other user may not be able to access the source files.
 
Back
Top Bottom