How to backup a directory (sub-directories/files) files from one server on to other ?
Hello,
Server A: /directory1/
Server B: /Backups/
i wanted to backup contents of /directory1 from "server A" on to "Server B" every 1 hour.
If there is any change in (only new/differences) contents on serverA (directory1/) supposed to be backeup on next run.
I did used rsync command to sync manually from server A to B using normal user. concept is working.
as a normal user
But i would like to automate this using scheduler using root.
My issue is,
I can not use password less SSH to automate this rysnc process (am familiar with password less ssh). Because direct/remote login disabled for root user. I do not want to enable it and sharing root public keys from one server to other server is not recommend in my situation.
Server A directory1/files owned by root.
Server B /Backups/ directory is also owned by root.
Can you please give me any idea on how to "set up password less automated rsync from server A to server B" with out enabling direct root login ?
thanks
Last edited by System Admin 77; 09-10-2015 at 01:25 PM..
You are specifying a connection to ServerB as user1, so the value for PermitRootLogin is ignored on ServerB. If you want it to run as root on ServerB and don't want to brute-force break your way around ssh, then you could:-
ssh as user1 and then use sudo
set the PermitRootLogin value to forced-commands-only This requires the command to be added to the authorized_keys file on ServerB
@blackrageous
Thanks for your help. Unfortunately i can not access the link now.
@rabtte1
Thanks for your response/help Robin.
first suggestion: we do not use sudo as of now. can we do it with su ?
second suggestion: looks interesting. But Do i need to set PermitRootLogin as YES ?
If that is the case, will it be a problem? If we are able to run "authorized_keys" file commands and block all other SSH/remote login traffic. that would be ok.
please suggest. thanks
---------- Post updated at 02:04 PM ---------- Previous update was at 01:34 PM ----------
I just got some other idea, like
server B: /Backups is owned by root.
If i can create new sub-directory called "userdir" under /Backups as root. And
change the permissions/ownership as " user:somegroup".
serverB:
Now i can share serverA root pub key with saccnt user on serverB. i can schedule a rsync script on serverA as root.
Is this ok ? sharing root "id_rsa.pub" key with a user on other server recommended ? please suggest.
Last edited by System Admin 77; 09-10-2015 at 04:14 PM..
You do not need to have PermitRootLogin Yes The forced-commands-only option means that you can only run the commands specified by the matching record in your authorized_keys file. This is from one of mine:-
This means that you can keep Security happy, because you still prevent login with ssh as root.
I suppose another way would be to use NFS and mount the ServerB directory on ServerA. You then could copy the data much more easily, as though it were a local resource. Do you know how to do this? It's a bit like mapping a network disk in Microsoft terms. This might give you security concerns though, as the data will be available on ServerA (subject to permissions) and you need to be careful with ownership. The files/directories ownership are stored as the UID & GID numbers and that can vary between servers, e.g. a file owned by bob, UID 1024 on ServerB may appear to be owned by sue on ServerA if sue has UID 1024 on ServerA.
Not sure if either of these suggestions helps or causes more headaches.
It looks good Robin. Thank you for your response/suggestion/help.
Yes, we already thought about NFS way.
Thanks for the "forced command" info. We will think about different approaches and proceed accordingly.
Find all files in the current directory only excluding hidden directories and files.
For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided.
`find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Can anyone come up with a unix command that lists
all the files, directories and sub-directories in the current directory
except a folder called log.?
Thank you in advance. (7 Replies)
Hi,
I have around 400 directories each one named as hour_1/ , hour_2/ .....hour_400/ and each of these contains two files, namely:
File1: hour_1.txt (in hour_1/) , hour_2.txt (in hour_2/) ....hour_400.txt (in hour_400/) etc...
File2: client_list_hour_1.txt (in hour_1/),... (7 Replies)
Hey guys,
I need to know how to locate all .htaccess files on the server and make a backup of them in the folder they reside before I run a script to modify all of them.
So basically taking dir1/.htaccess and copying it as dir1/.htaccess_bk
dir2/.htaccess copying as dir2/.htaccess_bk... (5 Replies)
i have a c-shell script.
and i pass it one or two arguments
the first argument is the directory
the second is the "-r"
now,
if i pass it only one, it searches the files ending in txt in that directory
if i pass it two parameters, like "temp" and "-r"
i want it to go through all the files and... (1 Reply)
I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together.
I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
So I am not sure if this should go in the shell forum or in the beginners. It is my first time posting on these forums.
I have a directory, main_dir lets say, with multiple sub directories (one_dir through onehundred_dir for example) and in each sub directory there is a test.txt. How would one... (2 Replies)
Hello,
Using the instruction mget (within ftp) and with "Interactive mode off", I want to get all files from directory (DirAA), but not the files in sub-directories.
The files names don't follow any defined rule, so they can be just letters without (.) period
Directory structure example: ... (0 Replies)
I want to know how many directories and files are there in a directory and if the sub directory have any files i also need that also .
I have done this far .... (4 Replies)