Spearfoot

Save FreeNAS configuration file

Sep 2nd, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Copies the FreeNAS settings file to a destination you specify, using a
  4. # filenaming scheme concatenating the hostname, FreeNAS version, and
  5. # current date. Strips any parentheses and replaces any spaces in the
  6. # resulting filename with '-' characters. Removes prior settings files
  7. # 90 days old or older after copying the current settings.
  8.  
  9. # Tested with versions 9.3.x and 9.10. You must modify the DEST_DIR
  10. # variable below to match your desired copy destination.
  11.  
  12. # The source FreeNAS configuration database file:
  13.  
  14. SRC_FILE="/data/freenas-v1.db"
  15.  
  16. # Form the destination filename - edit DEST_DIR here:
  17.  
  18. DEST_DIR="/mnt/tank/sysadmin/config"
  19. DEST_HOST=$(hostname -s)
  20. DEST_VERSION=$(cat /etc/version | sed -e 's/ /-/' | sed -e 's/(//' | sed -e 's/)//')
  21. DEST_DATE=$(date +%Y%m%d%H%M%S)
  22. DEST_FILE="$DEST_HOST"-"$DEST_VERSION"-"$DEST_DATE".db
  23.  
  24. echo "Backup configuration database file: $DEST_FILE"
  25.  
  26. # Copy the source to the destination:
  27.  
  28. cp "$SRC_FILE" "$DEST_DIR"/"$DEST_FILE"
  29.  
  30. # Remove prior versions in the destination directory that are 90 days old or older:
  31.  
  32. $(find "$DEST_DIR" -mtime +90 -name "*.db" -exec bash -c 'rm {}' \;)
Add Comment
Please, Sign In to add comment