mirror of
https://github.com/femtofox/femtofox.git
synced 2026-11-28 19:06:44 -05:00
Added Backup and Restore Scripts
This commit is contained in:
parent
1fd343fadf
commit
4ba416934a
3 changed files with 121 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
.DS_Store
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
# Backup Script
|
||||
# This script performs the following steps:
|
||||
# 1. Checks if the backup volume (/mnt/usb) is mounted.
|
||||
# 2. If a folder named "femto" already exists at /mnt/usb, it moves that folder
|
||||
# to /mnt/usb/backups with a timestamp appended.
|
||||
# 3. Copies /opt/meshing-around/config.ini (if it exists) to /home/femto/ with a date appended.
|
||||
# 4. Runs the meshtastic export-config command to save a node backup in /home/femto/.
|
||||
# 5. Copies any configuration files from /etc/meshtasticd/config.d/ to /home/femto/meshConfig/.
|
||||
# 6. Uses rsync to back up the /home/femto folder to /mnt/usb/femto (the most recent backup).
|
||||
|
||||
# Set a date variable (format: YYYYMMDD_HHMMSS)
|
||||
DATE=$(date +"%Y%m%d_%H%M%S")
|
||||
|
||||
# Define paths
|
||||
VOLUME="/mnt/usb"
|
||||
USB_FEMTO="$VOLUME/femto"
|
||||
USB_BACKUPS="$VOLUME/backups"
|
||||
HOME_FEMTO="/home/femto"
|
||||
|
||||
# 1. Check if the volume is mounted
|
||||
if mountpoint -q "$VOLUME"; then
|
||||
echo "Volume $VOLUME is mounted."
|
||||
else
|
||||
echo "Error: Volume $VOLUME is not mounted. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. If /mnt/usb/femto exists, move it to /mnt/usb/backups with a date appended
|
||||
if [ -d "$USB_FEMTO" ]; then
|
||||
echo "Existing backup found at $USB_FEMTO. Moving it to $USB_BACKUPS with timestamp."
|
||||
sudo mkdir -p "$USB_BACKUPS"
|
||||
sudo mv "$USB_FEMTO" "$USB_BACKUPS/femto_backup_$DATE"
|
||||
fi
|
||||
|
||||
# 3. Check if the config file exists and copy it to /home/femto with date appended
|
||||
CONFIG_SRC="/opt/meshing-around/config.ini"
|
||||
if [ -f "$CONFIG_SRC" ]; then
|
||||
CONFIG_DEST="$HOME_FEMTO/config.ini_$DATE"
|
||||
echo "Copying $CONFIG_SRC to $CONFIG_DEST"
|
||||
cp "$CONFIG_SRC" "$CONFIG_DEST"
|
||||
else
|
||||
echo "Config file $CONFIG_SRC not found. Skipping config copy."
|
||||
fi
|
||||
|
||||
# 4. Run the meshtastic export-config command and save its output to a node backup file
|
||||
NODE_BACKUP="$HOME_FEMTO/nodeBackup_$DATE.yaml"
|
||||
echo "Running meshtastic export-config; outputting to $NODE_BACKUP"
|
||||
meshtastic --host localhost --export-config > "$NODE_BACKUP"
|
||||
|
||||
# 5. Back up any configuration files from /etc/meshtasticd/config.d/ to /home/femto/meshConfig/
|
||||
CONFIG_D="/etc/meshtasticd/config.d"
|
||||
MESH_CONFIG="$HOME_FEMTO/meshConfig"
|
||||
if [ -d "$CONFIG_D" ] && [ "$(ls -A "$CONFIG_D")" ]; then
|
||||
echo "Copying files from $CONFIG_D to $MESH_CONFIG"
|
||||
mkdir -p "$MESH_CONFIG"
|
||||
cp "$CONFIG_D"/* "$MESH_CONFIG"/
|
||||
else
|
||||
echo "No files found in $CONFIG_D. Skipping config.d backup."
|
||||
fi
|
||||
|
||||
# 6. Use rsync to back up /home/femto to /mnt/usb/femto (the most recent backup)
|
||||
echo "Starting rsync backup of $HOME_FEMTO to $USB_FEMTO"
|
||||
sudo rsync -a --no-o --no-g --info=progress2 \
|
||||
--exclude="lost+found" --exclude=".cache" --exclude=".zgenom" --exclude=".zcompdump" \
|
||||
"$HOME_FEMTO"/ "$USB_FEMTO"/
|
||||
|
||||
echo "Backup process completed."
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#!/bin/bash
|
||||
# Restore Script
|
||||
# This script performs the following:
|
||||
# 1. Restores the /home/femto directory from the latest backup at /mnt/usb/femto.
|
||||
# 2. Restores configuration files from the backup directory (/home/femto/meshConfig)
|
||||
# back to their original location (/etc/meshtasticd/config.d/).
|
||||
# 3. Cleans up additional backup files created during the backup process.
|
||||
# 4. Restores owner of Home directory
|
||||
#
|
||||
# Note: The /mnt/usb/backups folder is not touched during restoration.
|
||||
|
||||
# Define paths
|
||||
VOLUME="/mnt/usb"
|
||||
USB_FEMTO="$VOLUME/femto"
|
||||
HOME_FEMTO="/home/femto"
|
||||
MESH_CONFIG_BACKUP="$HOME_FEMTO/meshConfig"
|
||||
DEST_CONFIG="/etc/meshtasticd/config.d"
|
||||
|
||||
# Check if the latest backup exists
|
||||
if [ ! -d "$USB_FEMTO" ]; then
|
||||
echo "Error: Latest backup directory $USB_FEMTO not found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Restore the home directory from the latest backup
|
||||
echo "Restoring home directory from $USB_FEMTO to $HOME_FEMTO"
|
||||
sudo rsync -a --info=progress2 "$USB_FEMTO"/ "$HOME_FEMTO"/
|
||||
echo "Home directory restore completed."
|
||||
|
||||
# Restore configuration files to /etc/meshtasticd/config.d/
|
||||
if [ -d "$MESH_CONFIG_BACKUP" ]; then
|
||||
echo "Restoring configuration files from $MESH_CONFIG_BACKUP to $DEST_CONFIG"
|
||||
# Ensure the destination directory exists (requires sudo if /etc is not writable)
|
||||
sudo mkdir -p "$DEST_CONFIG"
|
||||
sudo cp -r "$MESH_CONFIG_BACKUP/"* "$DEST_CONFIG"/
|
||||
echo "Configuration files restored to $DEST_CONFIG."
|
||||
else
|
||||
echo "No meshConfig backup found in $HOME_FEMTO. Skipping configuration restoration."
|
||||
fi
|
||||
|
||||
# Clean up additional backup files added to the home directory during backup
|
||||
echo "Cleaning up additional backup files in $HOME_FEMTO"
|
||||
#rm -f "$HOME_FEMTO"/nodeBackup_*.yaml
|
||||
#rm -f "$HOME_FEMTO"/config.ini_*
|
||||
rm -rf "$HOME_FEMTO"/meshConfig
|
||||
echo "Cleanup completed."
|
||||
|
||||
# Update Owner of Home folder and all sub-folders
|
||||
echo "Updating Owner of Home Directory"
|
||||
sudo chown -R femto:femto /home/femto
|
||||
|
||||
echo "Restore process completed."
|
||||
Loading…
Add table
Add a link
Reference in a new issue