Is it possible to take a folder on an Ubuntu server that is full of files and sub-folders, hundreds of them and there are special file and folder owner and permissions set all within this folder.

To give a better explanation, I have a folder on an Ubuntu server that has the SugarCRM application installed in it.

I a wanting to know if there is an easy method to build some wort of script that will go through and set all the file/folder owners and permissions as they currently are on the server to a future install.

So basically if I were to simply copy the sugarcrm folder and paste it on another server, the script could go through and set all the permissions and owners the exact same as the original server had them?

My ultimate goal is to build a bash script that can use RSync on the Ubuntu server to make a database back and file backup and then RSync them to a remote backup server over SSH. So far I have seen how to generate the database backup files as well as the folder of files/folders and then rsync them.

My problem is on the destination server, I do not know how I can restore using my backup files and have it keep the origin servers file and folder owner and permissions. Just restoring and overwriting the files would likely retain the permission and owners however I would like to know how to make it work where I could restore to brand new server using my backup files and have all the proper permissions and owners set!


You simply use a tool that preserves the permissions and owners when you copy the files.

The classic tar stores owners and permissions in the archive itself and using the -p or --preserve-permissions will preserve and/or restore them when you extract files from that backup archive.

Other tools also preserve owner and permission information, either by default or when you set the correct flags, check their manual pages.

rsync for instance has a whole host of options for doing so:

 -H, --hard-links            preserve hard links
 -p, --perms                 preserve permissions
 -E, --executability         preserve executability
     --chmod=CHMOD           affect file and/or directory permissions
 -A, --acls                  preserve ACLs (implies -p)
 -X, --xattrs                preserve extended attributes
 -o, --owner                 preserve owner (super-user only)
 -g, --group                 preserve group
     --devices               preserve device files (super-user only)
     --specials              preserve special files
 -D                          same as --devices --specials
 -t, --times                 preserve modification times

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.