Skip to content

Instantly share code, notes, and snippets.

@NoSubstitute
Forked from zk-1/gam-batch-archive.sh
Last active July 21, 2022 21:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoSubstitute/6ddf2c38dc85f8e34f6754d88a395971 to your computer and use it in GitHub Desktop.
Save NoSubstitute/6ddf2c38dc85f8e34f6754d88a395971 to your computer and use it in GitHub Desktop.
This scripts allows the batch archival of Google Workspace accounts, via the accompanying gam-archive.sh script
#!/usr/bin/env bash
# Name: gam-batch-archive.sh
# Usage: cat archive_user_list.txt | gam-batch-archive.sh mail|drive|both
# Description: This scripts allows the batch archival of Google Workspace accounts, via the accompanying gam-archive.sh script
# Author: Zoë Kelly (zoe@starshade.ca), Kim Nilsson (github@no-substitute.com)
# License: MIT
# Created: 2020
# Updated: 2022-07-19
## Note: The gam-archive.sh script should be in the same folder or (preferably) in $PATH.
## Note: The input file should have a list of Google Workspace users to be archived, each on a new line.
## Note: The email prefix should be used, i.e. jsmith. The list should only have usernames, no header.
# Where to put logs
# You should definitely use a better path for this, and check the log after running the script.
log_path="$HOME/Desktop"
# --- --- --- --- --- --- --- --- --- ---
today_stamp=$(date "+%d-%m-%Y")
usage="Usage: cat archive_user_list.txt | $(basename "$0") mail|drive|both"
[ ! -t 0 ] && : || echo "No input detected - $usage - Press ctrl + C now"
the_users=$(cat /dev/stdin)
# If no paramater given, print usage and exit
if [ $# -lt 1 ]; then
echo "$usage"
exit
fi
export_type="$1"
for i in $the_users ; do
gam-archive.sh "$i" "$export_type"
echo "$today_stamp - Archived - $i" >> "$log_path"/gam-batch-archive.log
done
echo "Done. If there were no errors, it probably went fine."
echo "Log file: $log_path/gam-batch-archive.log"
exit 0
@NoSubstitute
Copy link
Author

Adjusted "G Suite" to "Google Workspace", added a few informative notes, removed the ./ reference to gam-archive.sh, added double quoting for variables according to https://www.shellcheck.net/wiki/SC2086, and adjusted backtick commands according to https://www.shellcheck.net/wiki/SC2006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment