Clone ownership and group of coincident name files and folders between two servers

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I need to sync only ownership and group of each file and dir between two server filesystems. That's to say if I have server A and server B, I don't need and don't want to copy data from one server to other, I need to set the same owner and group from each file in B that exists in A. If a file/dir doesn't exist in A, or viceversa, I don't need to do nothing about, only to change owner and group of every file and directory that exists in both servers to the one of the file/dir in server A. I know that "chown --reference" make that, but I don't know how to use it for change according to other files and directories.



I wish I explained my question correctly.



Please, any suggestion?



Thanks in advance







share|improve this question




















  • Just owner and group, and neither permission nor SELinux security context nor ACLs? (Just checking.)
    – Ulrich Schwarz
    Feb 8 at 8:24










  • Yes, only OWNER and GROUP, not data content or permissions
    – Rafael Linux User
    Feb 8 at 8:28














up vote
1
down vote

favorite












I need to sync only ownership and group of each file and dir between two server filesystems. That's to say if I have server A and server B, I don't need and don't want to copy data from one server to other, I need to set the same owner and group from each file in B that exists in A. If a file/dir doesn't exist in A, or viceversa, I don't need to do nothing about, only to change owner and group of every file and directory that exists in both servers to the one of the file/dir in server A. I know that "chown --reference" make that, but I don't know how to use it for change according to other files and directories.



I wish I explained my question correctly.



Please, any suggestion?



Thanks in advance







share|improve this question




















  • Just owner and group, and neither permission nor SELinux security context nor ACLs? (Just checking.)
    – Ulrich Schwarz
    Feb 8 at 8:24










  • Yes, only OWNER and GROUP, not data content or permissions
    – Rafael Linux User
    Feb 8 at 8:28












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I need to sync only ownership and group of each file and dir between two server filesystems. That's to say if I have server A and server B, I don't need and don't want to copy data from one server to other, I need to set the same owner and group from each file in B that exists in A. If a file/dir doesn't exist in A, or viceversa, I don't need to do nothing about, only to change owner and group of every file and directory that exists in both servers to the one of the file/dir in server A. I know that "chown --reference" make that, but I don't know how to use it for change according to other files and directories.



I wish I explained my question correctly.



Please, any suggestion?



Thanks in advance







share|improve this question












I need to sync only ownership and group of each file and dir between two server filesystems. That's to say if I have server A and server B, I don't need and don't want to copy data from one server to other, I need to set the same owner and group from each file in B that exists in A. If a file/dir doesn't exist in A, or viceversa, I don't need to do nothing about, only to change owner and group of every file and directory that exists in both servers to the one of the file/dir in server A. I know that "chown --reference" make that, but I don't know how to use it for change according to other files and directories.



I wish I explained my question correctly.



Please, any suggestion?



Thanks in advance









share|improve this question











share|improve this question




share|improve this question










asked Feb 8 at 8:17









Rafael Linux User

162




162











  • Just owner and group, and neither permission nor SELinux security context nor ACLs? (Just checking.)
    – Ulrich Schwarz
    Feb 8 at 8:24










  • Yes, only OWNER and GROUP, not data content or permissions
    – Rafael Linux User
    Feb 8 at 8:28
















  • Just owner and group, and neither permission nor SELinux security context nor ACLs? (Just checking.)
    – Ulrich Schwarz
    Feb 8 at 8:24










  • Yes, only OWNER and GROUP, not data content or permissions
    – Rafael Linux User
    Feb 8 at 8:28















Just owner and group, and neither permission nor SELinux security context nor ACLs? (Just checking.)
– Ulrich Schwarz
Feb 8 at 8:24




Just owner and group, and neither permission nor SELinux security context nor ACLs? (Just checking.)
– Ulrich Schwarz
Feb 8 at 8:24












Yes, only OWNER and GROUP, not data content or permissions
– Rafael Linux User
Feb 8 at 8:28




Yes, only OWNER and GROUP, not data content or permissions
– Rafael Linux User
Feb 8 at 8:28










1 Answer
1






active

oldest

votes

















up vote
2
down vote













Assuming that you don't mind trying to set ownerships on files that already have them correctly, I guess you could run something along the lines of



/bin/stat --format 'chown %u:%g %n' ~/.bash*


on server A, which will give you a list of chown commands to execute on server B. (You could pipe the whole thing through | ssh user@serverB.)



You'll get the occasional error for files that don't exist on B, but that would be harmless.






share|improve this answer




















  • I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
    – Rafael Linux User
    Feb 8 at 8:40










  • @RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
    – JJoao
    Feb 8 at 8:54










  • Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
    – Rafael Linux User
    Feb 8 at 9:27










  • Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
    – Rafael Linux User
    Feb 8 at 9:29






  • 1




    @JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
    – Ulrich Schwarz
    Feb 8 at 11:57










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422728%2fclone-ownership-and-group-of-coincident-name-files-and-folders-between-two-serve%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













Assuming that you don't mind trying to set ownerships on files that already have them correctly, I guess you could run something along the lines of



/bin/stat --format 'chown %u:%g %n' ~/.bash*


on server A, which will give you a list of chown commands to execute on server B. (You could pipe the whole thing through | ssh user@serverB.)



You'll get the occasional error for files that don't exist on B, but that would be harmless.






share|improve this answer




















  • I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
    – Rafael Linux User
    Feb 8 at 8:40










  • @RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
    – JJoao
    Feb 8 at 8:54










  • Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
    – Rafael Linux User
    Feb 8 at 9:27










  • Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
    – Rafael Linux User
    Feb 8 at 9:29






  • 1




    @JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
    – Ulrich Schwarz
    Feb 8 at 11:57














up vote
2
down vote













Assuming that you don't mind trying to set ownerships on files that already have them correctly, I guess you could run something along the lines of



/bin/stat --format 'chown %u:%g %n' ~/.bash*


on server A, which will give you a list of chown commands to execute on server B. (You could pipe the whole thing through | ssh user@serverB.)



You'll get the occasional error for files that don't exist on B, but that would be harmless.






share|improve this answer




















  • I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
    – Rafael Linux User
    Feb 8 at 8:40










  • @RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
    – JJoao
    Feb 8 at 8:54










  • Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
    – Rafael Linux User
    Feb 8 at 9:27










  • Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
    – Rafael Linux User
    Feb 8 at 9:29






  • 1




    @JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
    – Ulrich Schwarz
    Feb 8 at 11:57












up vote
2
down vote










up vote
2
down vote









Assuming that you don't mind trying to set ownerships on files that already have them correctly, I guess you could run something along the lines of



/bin/stat --format 'chown %u:%g %n' ~/.bash*


on server A, which will give you a list of chown commands to execute on server B. (You could pipe the whole thing through | ssh user@serverB.)



You'll get the occasional error for files that don't exist on B, but that would be harmless.






share|improve this answer












Assuming that you don't mind trying to set ownerships on files that already have them correctly, I guess you could run something along the lines of



/bin/stat --format 'chown %u:%g %n' ~/.bash*


on server A, which will give you a list of chown commands to execute on server B. (You could pipe the whole thing through | ssh user@serverB.)



You'll get the occasional error for files that don't exist on B, but that would be harmless.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 8 at 8:30









Ulrich Schwarz

8,87512643




8,87512643











  • I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
    – Rafael Linux User
    Feb 8 at 8:40










  • @RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
    – JJoao
    Feb 8 at 8:54










  • Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
    – Rafael Linux User
    Feb 8 at 9:27










  • Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
    – Rafael Linux User
    Feb 8 at 9:29






  • 1




    @JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
    – Ulrich Schwarz
    Feb 8 at 11:57
















  • I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
    – Rafael Linux User
    Feb 8 at 8:40










  • @RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
    – JJoao
    Feb 8 at 8:54










  • Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
    – Rafael Linux User
    Feb 8 at 9:27










  • Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
    – Rafael Linux User
    Feb 8 at 9:29






  • 1




    @JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
    – Ulrich Schwarz
    Feb 8 at 11:57















I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
– Rafael Linux User
Feb 8 at 8:40




I don't mind to "re-set" files that have yet the correct owner and group, as you correctly thought. I think your idea is fantastic, I didn't imagine to use "stat". I was wondering on using "rsync" combined with "chown --reference", but your solution is less risky. I'll give you news about the task. Thank you!!
– Rafael Linux User
Feb 8 at 8:40












@RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
– JJoao
Feb 8 at 8:54




@RafaelLinuxUser, try stat --format 'chown %U:%G "%n"' to have names
– JJoao
Feb 8 at 8:54












Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
– Rafael Linux User
Feb 8 at 9:27




Thank you!! I remove my question, cause I should have investigate more on the paremeters of "stat" before asking.
– Rafael Linux User
Feb 8 at 9:27












Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
– Rafael Linux User
Feb 8 at 9:29




Based on Ulrich solution, I have this sentence: "find / ! -user root -or ! -group root | xargs stat --format 'chown %U:%G %n' ", but , please, how to redirect to a txt file? I tried adding "> text.txt" but didn't worked.
– Rafael Linux User
Feb 8 at 9:29




1




1




@JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
– Ulrich Schwarz
Feb 8 at 11:57




@JJoao: yes, always a tricky issue if you don't know if uid/guid assignments are the same for both servers.
– Ulrich Schwarz
Feb 8 at 11:57












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422728%2fclone-ownership-and-group-of-coincident-name-files-and-folders-between-two-serve%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay