Skip to content

Instantly share code, notes, and snippets.

@Staubgeborener
Last active January 11, 2024 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Staubgeborener/4f1ed837870441478ad039145797ee4b to your computer and use it in GitHub Desktop.
Save Staubgeborener/4f1ed837870441478ad039145797ee4b to your computer and use it in GitHub Desktop.
Local klipper backup script without git. Original script: https://github.com/Staubgeborener/klipper-backup/
# Indivdual file syntax:
# Note: script.sh starts its search in $HOME which is /home/{username}/
# Using below example the script will search for: /home/{username}/printer_data/config/printer.cfg
#path_printercfg=printer_data/config/printer.cfg
# Backup folder syntax:
# Note: script.sh starts its search in $HOME which is /home/{username}/
# Using below example the script will search for: /home/{username}/printer_data/config/*
# The star denotes a wildcard meaning that any and all files in the folder will be selected
path_klipperdata=printer_data/config/*
backup_folder=config_backup/klipper
#!/usr/bin/env bash
# Set parent directory path
parent_path=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)
# Initialize variables from .env file
source "$parent_path"/.env
# Change directory to parent path
cd "$parent_path" || exit
# optional: removing backup folder to get "clean" backup files
# rm -rf $HOME/$backup_folder/
# Check if backup folder exists, create one if it does not
if [ ! -d "$HOME/$backup_folder" ]; then
mkdir -p "$HOME/$backup_folder"
fi
while IFS= read -r path; do
# Iterate over every file in the path
for file in $HOME/$path; do
# Check if it's a symbolic link
if [ -h "$file" ]; then
echo "Skipping symbolic link: $file"
# Check if file is an extra backup of printer.cfg moonraker/klipper seems to like to make 4-5 of these sometimes no need to back them all up as well.
elif [[ $(basename "$file") =~ ^printer-[0-9]+_[0-9]+\.cfg$ ]]; then
echo "Skipping file: $file"
else
cp $file $HOME/$backup_folder/
fi
done
done < <(grep -v '^#' "$parent_path/.env" | grep 'path_' | sed 's/^.*=//')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment