diff --git a/create_zfs_datasets.sh b/create_zfs_datasets.sh index c6b70dd0e2d9b8a9577f15e47efaf4a0e1d60f83..1e46050138d8a68b9b0a1497c048b66b2f53c96c 100755 --- a/create_zfs_datasets.sh +++ b/create_zfs_datasets.sh @@ -6,7 +6,7 @@ print_help() { echo "Usage: $0 --env-file=filename" } -OPTIONS=$(getopt -o he: --long env-file:,help,zpool:,top-level-dataset: -n "$0" -- "$@") +OPTIONS=$(getopt -o he:s --long env-file:,help,zpool:,top-level-dataset:,skip-empty-snapshot -n "$0" -- "$@") if [ $? -ne 0 ]; then print_help @@ -17,6 +17,7 @@ ZPOOL="" TOP_LEVEL_DATASET="" ZPOOL_MOUNT_POINT="" TOP_LEVEL_DATASET_MOUNTPOINT="" +SKIP_EMPTY_SNAPSHOT=false eval set -- "$OPTIONS" @@ -34,6 +35,10 @@ while true; do TOP_LEVEL_DATASET="$2" shift 2 ;; + --skip-empty-snapshot|-s) + SKIP_EMPTY_SNAPSHOT=true + shift + ;; --help|-h) print_help exit 0 @@ -134,5 +139,9 @@ chown -R 1000:100 "$TOP_LEVEL_DATASET_MOUNTPOINT/logs" # 105:109 is postgres:postgres inside the container chown -R 105:109 "$TOP_LEVEL_DATASET_MOUNTPOINT/logs/postgresql" "$TOP_LEVEL_DATASET_MOUNTPOINT/logs/pgbadger" -# Create a snapshot called 'empty' -./snapshot_zfs_datasets.sh empty +if [ "$SKIP_EMPTY_SNAPSHOT" = false ]; then + # Create a snapshot called 'empty' + ./snapshot_zfs_datasets.sh empty +else + echo "Skipping creation of 'empty' snapshot." +fi diff --git a/snapshot_zfs_datasets.sh b/snapshot_zfs_datasets.sh index 960f697ccce7ca12e1fe917a744a2957b34dceee..1e0791c023fd23df2e6fe7a562a9fc4f387c51aa 100755 --- a/snapshot_zfs_datasets.sh +++ b/snapshot_zfs_datasets.sh @@ -13,9 +13,10 @@ print_help() { echo " dataset, then swap back afterwards. That way the large logs files aren't" echo " of the snapshots. This is a lot faster, but makes managing datasets more" echo " complicated, so only use it if you really need to" + echo " --force, -f continue without prompting, even if warnings are detected" } -OPTIONS=$(getopt -o he:pt:l: --long env-file:,help,zpool:,top-level-dataset:,public-snapshot,temp-dir:,swap-logs-with-dataset: -n "$0" -- "$@") +OPTIONS=$(getopt -o he:pt:l:f --long env-file:,help,zpool:,top-level-dataset:,public-snapshot,temp-dir:,swap-logs-with-dataset:,force -n "$0" -- "$@") if [ $? -ne 0 ]; then print_help @@ -29,6 +30,7 @@ TOP_LEVEL_DATASET_MOUNTPOINT="" PUBLIC_SNAPSHOT=0 SWAP_LOGS_DATASET="" TMPDIR=/tmp +FORCE=0 eval set -- "$OPTIONS" @@ -58,6 +60,10 @@ while true; do SWAP_LOGS_DATASET="$2" shift 2 ;; + --force|-f) + FORCE=1 + shift 2 + ;; --help|-h) print_help exit 0 @@ -141,7 +147,7 @@ if [ "$SNAPSHOT_NAME" != "empty" ]; then fi last_shared_memory_write=$(stat -c %Y "${TOP_LEVEL_DATASET_MOUNTPOINT}/shared_memory/shared_memory.bin") - last_blockchain_write=$(find "${TOP_LEVEL_DATASET_MOUNTPOINT}/blockchain" -type f -printf '%T@\n' | sort -n | tail -1) + last_blockchain_write=$(find "${TOP_LEVEL_DATASET_MOUNTPOINT}/blockchain" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1) if [ -z "$last_blockchain_write" ]; then echo "Warning: No files found in the blockchain directory" @@ -152,12 +158,16 @@ if [ "$SNAPSHOT_NAME" != "empty" ]; then if [ $time_diff -gt 300 ] || [ $time_diff -lt -300 ]; then echo "Warning: The shared_memory.bin file was not written to within 5 minutes of the last write to a file in the blockchain directory." - read -p "Do you want to continue? (y/n): " choice - case "$choice" in - y|Y ) echo "Continuing...";; - n|N ) echo "Aborting."; exit 1;; - * ) echo "Invalid input. Aborting."; exit 1;; - esac + if [ "$FORCE" -eq 1 ]; then + echo "Continuing due to --force option." + else + read -p "Do you want to continue? (y/n): " choice + case "$choice" in + y|Y ) echo "Continuing...";; + n|N ) echo "Aborting."; exit 1;; + * ) echo "Invalid input. Aborting."; exit 1;; + esac + fi fi fi