1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

rsync help

Discussion in 'Linux & Open Source' started by Mason64, Feb 13, 2019.

  1. Mason64

    Hitman

    Joined: Jan 16, 2006

    Posts: 918

    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
     
  2. shiver

    Hitman

    Joined: Jun 13, 2007

    Posts: 749

    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
     
  3. SoundsGood

    Wise Guy

    Joined: May 16, 2008

    Posts: 2,133

    rsync -zavP -e 'ssh -p 2222' root@IP:/root/home/clickit/ /home/backup/
     
  4. pete910

    Wise Guy

    Joined: Oct 3, 2013

    Posts: 2,469

    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.
     
  5. Mason64

    Hitman

    Joined: Jan 16, 2006

    Posts: 918

    Location: North Wales

    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



    Do you know where i can learn about key files?
     
  6. pete910

    Wise Guy

    Joined: Oct 3, 2013

    Posts: 2,469

  7. SoundsGood

    Wise Guy

    Joined: May 16, 2008

    Posts: 2,133

    -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
     
  8. Mason64

    Hitman

    Joined: Jan 16, 2006

    Posts: 918

    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?
     
  9. Steveocee

    Mobster

    Joined: Nov 5, 2011

    Posts: 4,669

    Location: Derbyshire

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

    Hitman

    Joined: Jan 16, 2006

    Posts: 918

    Location: North Wales

    Thanks Steve i will look in to that.
     
  11. pete910

    Wise Guy

    Joined: Oct 3, 2013

    Posts: 2,469

    What Steveocee said :D

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

    Wise Guy

    Joined: Nov 2, 2008

    Posts: 2,422

    Location: The ether

    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: Aug 13, 2019
  13. memyselfandi

    Sgarrista

    Joined: Oct 10, 2005

    Posts: 8,436

    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.