Jump to content

Button Script - backup all /etc/config files into a subfolder /backup


Recommended Posts

#!/bin/bash

#####################################################################
############## Configuration Backup and Restore Script #############
#####################################################################

# List of configuration files to backup and restore
config_files=(
    "autossh"
    "dhcp"
    "firewall"
    "fstab"
    "pineap"
    "network"
    "system"
    "wireless"
)

# Backup directory
backup_dir="/etc/config/backup"

# Function to backup configuration files
backup_config() {
    if [ ! -d "$backup_dir" ]; then
        mkdir "$backup_dir"
    fi

    for file in "${config_files[@]}"; do
        backup_file="$backup_dir/$file.backup"
        if [ -f "/etc/config/$file" ]; then
            if [ ! -f "$backup_file" ]; then
                cp "/etc/config/$file" "$backup_file"
                echo "Created backup for $file configuration at $backup_file"
            else
                echo "Backup for $file configuration already exists at $backup_file"
            fi
        else
            echo "Warning: /etc/config/$file does not exist, skipping backup."
        fi
    done
}

# Function to restore configuration files
restore_config() {
    for file in "${config_files[@]}"; do
        backup_file="$backup_dir/$file.backup"
        if [ -f "$backup_file" ]; then
            cp "$backup_file" "/etc/config/$file"
            echo "Restored $file configuration from $backup_file"
        else
            echo "Warning: $backup_file does not exist, skipping restore."
        fi
    done
}

# Function to run the LED color sequence
run_led_sequence() {
    # Color sequence
    colors=("G" "Y" "G" "Y" "G" "Y" "G" "B")

    # Duration for each color (in seconds)
    duration=0.1

    for color in "${colors[@]}"; do
        LED $color VERYFAST
        sleep $duration
        LED $color SOLID
        sleep $duration
    done

    LED B SUCCESS
}

# Main script execution
backup_config
restore_config
run_led_sequence

Button script to backup all settings to a subfolder /backup and then do some randomized diod blinking.

Backup is done if there are no backup files, otherwise it creates the files and flashes. usefull if you get locked outof root portal after playing with iptables instead of flashing recovery.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...