InfoGlobe Open Source Tools

These tools, while extremely helpful, are provided without any warranty.  Software on this page is copyright 2008 InfoGlobe Communications and is released under the GPL (general public license).  You are free to copy and use it, as long as you don't charge for it, nor include it in any software which is not licensed under the GPL.

At InfoGlobe, we run and maintain Linux servers for clients abroad.  To contribute back to the Open Source community, here are some tools we've developed, which we find quite useful.  Hopefully they help you as much as they've helped us.

save_permission_tree.sh

Shell (BASH) script to traverse a complete directory and create a gzipped text file containing permissions and owner information for files and directories in the tree.  This script is used in conjunction with restore_permission_tree.pl below to save & restore the permission and owner information.

We use rsync to create backup images of OpenVZ hosts on our servers.  Since we rsync to the backup host as a non-root user, it is not possible to store the backup files with the same owner as on the host.  Further, since we allow web-access to the backups, we have to alter the permissions on the backed-up files to allow the backup box's web server read them.

Before running our rsync backup, our cron job runs this script as below, saving all permission and owner information.

The cron'd script:

for i in `find /vz/private/* -maxdepth 0 -type d`; do
  echo saving permissions tree in $i
  cd $i
  /vz/private/save_permission_tree.sh .file_permissions.txt.gz
done
restore_permission_tree.pl

PERL program to restore a permission tree from a textfile generated by the above script.  To reset permissions, run it like this:

  1. CD into the base directory where the permissions save file was created
  2. zcat [permissions file] | ./restore_permission_tree.pl

The program will display each file's information and shell out to run chmod and chown commands as appropriate.  If the destination file to be chmodded/chowned doesn't exist, those commands fail and the script moves on.  To restrict the script to change UID/GID/Permissions on a set of files, you can pipe the zcat output through grep.

© 2010 InfoGlobe Communications, all rights reserved.