Recursive ACL script: Difference between revisions

From SciNet Users Documentation
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
===Recursive ACL script ===
===Recursive ACL script ===
You may use/adapt one of the following bash scripts to recursively add or remove ACL attributes using gpfs built-in commands
The GPFS-specific <code>mmputacl</code> commands used by these scripts are not
available on the current VAST file systems. For ACL management, use POSIX
<code>setfacl</code> and <code>getfacl</code>. See the Alliance wiki:


====Courtesy of Gabriel Devenyi====
https://docs.alliancecan.ca/wiki/Data_management_at_Trillium#File_ownership_management_and_access_control_lists
 
<pre>
#!/bin/bash
# USAGE
#    - on one directory:    ./set_acl.sh aclfile dir_name
#    - on more directories:  ./set_acl.sh aclfile dir1_name dir2_name ...
#
# Based on a contributed script by Gabriel Devenyi.
#
 
set -euo pipefail
aclfile="$1"
shift
 
for dir in "$@"
do
    find "${dir}" -type d -exec mmputacl -i "${aclfile}" {} \; -exec mmputacl -d -i "${aclfile}" {} \;
    find "${dir}" -type f -exec mmputacl -i "${aclfile}" {} \;
done
</pre>
 
====Courtesy of Agata Disks====
 
(http://csngwinfo.in2p3.fr/mediawiki/index.php/GPFS_ACL)
 
This script is a bit more verbose and precise in its error messages
 
<pre>
#!/bin/bash
# USAGE
#    - on one directory:    ./set_acl.sh dir_name
#    - on more directories:  ./set_acl.sh 'dir_nam*'
#
 
# Path of the file that contains the ACL
ACL_FILE_PATH=/agatadisks/data/acl_file.acl
 
# Directories onto the ACLs have to be set
dirs=$1
 
# Recursive function that sets ACL to files and directories
set_acl () {
  curr_dir=$1
  for args in $curr_dir/*
  do
    if [ -f $args ]; then
      echo "ACL set on file $args"
      mmputacl -i $ACL_FILE_PATH $args
      if [ $? -ne 0 ]; then
        echo "ERROR: ACL not set on $args"
        exit -1
      fi
    fi
    if [ -d $args ]; then
      # Set Default ACL in directory
      mmputacl -i $ACL_FILE_PATH $args -d
      if [ $? -ne 0 ]; then
        echo "ERROR: Default ACL not set on $args"
        exit -1
      fi
      echo "Default ACL set on directory $args"
      # Set ACL in directory
      mmputacl -i $ACL_FILE_PATH $args
      if [ $? -ne 0 ]; then
        echo "ERROR: ACL not set on $args"
        exit -1
      fi
      echo "ACL set on directory $args"
      set_acl $args
    fi
  done
}
for dir in $dirs
do
  if [ ! -d $dir ]; then
    echo "ERROR: $dir is not a directory"
    exit -1
  fi
  set_acl $dir
done
exit 0
 
</pre>
 
[[Data Management#File/Ownership Management (ACL) |  BACK TO Data Management]]

Latest revision as of 14:54, 30 November 2026

Recursive ACL script

The GPFS-specific mmputacl commands used by these scripts are not available on the current VAST file systems. For ACL management, use POSIX setfacl and getfacl. See the Alliance wiki:

https://docs.alliancecan.ca/wiki/Data_management_at_Trillium#File_ownership_management_and_access_control_lists