23 lines
		
	
	
	
		
			527 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
	
		
			527 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/usr/bin/bash
 | |
| #
 | |
| # Backup and remove all student home directories.
 | |
| 
 | |
| set -eu
 | |
| 
 | |
| HDIRS='/home/'
 | |
| DIRS=()
 | |
| 
 | |
| for DIR in $(find $HDIRS -maxdepth 1 -mindepth 1 -type d) ; do
 | |
|     H="$(basename $DIR)"
 | |
|     if [[ "$H" =~ ^L_ ]] || [[ "$H" =~ ansible ]] ; then
 | |
| 	echo "Skipping home of '$H'."
 | |
| 	continue
 | |
|     fi
 | |
|     DIRS+=("$DIR") 
 | |
| done
 | |
| [[ "${#DIRS[@]}" -eq 0 ]] && exit 0
 | |
| 
 | |
| AR="homes_$(date -I).tar.gz"
 | |
| tar czf "$AR" -C "$HDIRS" --exclude='.[^/]*' \
 | |
|     -P --transform="s%$HDIRS%%" "${DIRS[@]}"
 | |
| echo "Create archive $AR containing: ${DIRS[@]}"
 | 
