Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ba2a512
Create tar_matching_dirs.sh
mgvv Aug 29, 2025
73d3f7c
Create menu.sh
mgvv Aug 29, 2025
726e822
Create main.sh
mgvv Aug 29, 2025
86ef28a
Create functions.sh
mgvv Aug 29, 2025
2adba93
Add files via upload
mgvv Aug 29, 2025
0cec2f3
Create nfs_export_setup.sh
mgvv Sep 10, 2025
ed982bf
Create README.md
mgvv Sep 10, 2025
8e1b05d
Create nfs_client_setup.sh
mgvv Sep 10, 2025
1d24004
Create README.md
mgvv Sep 10, 2025
a323fe7
Update nfs_client_setup.sh
mgvv Sep 10, 2025
539643c
Update README.md
mgvv Sep 10, 2025
4e7bc75
Create setup_x11_forwarding.sh
mgvv Sep 30, 2025
adba260
Delete SysInfoProject/X-11/setup_x11_forwarding.sh
mgvv Oct 9, 2025
0065809
Create setup_x11_forwarding.sh
mgvv Oct 9, 2025
baa34e6
Update setup_x11_forwarding.sh
mgvv Oct 9, 2025
ba0d1f6
Create top-swap.sh
mgvv Oct 9, 2025
811884f
Update top-swap.sh
mgvv Oct 9, 2025
cbe5d1c
Update top-swap.sh
mgvv Oct 9, 2025
bcbf747
Create README.md
mgvv Oct 9, 2025
afe84d8
Update README.md
mgvv Oct 9, 2025
25153c4
Update README.md
mgvv Oct 9, 2025
d3825a0
Create top-swap.sh
mgvv Oct 9, 2025
91de4a9
Delete SysInfoProject/mem_monitor/top-swap.sh
mgvv Oct 9, 2025
560f6fc
Create top-ram.sh
mgvv Oct 9, 2025
f987f67
Add files via upload
mgvv Oct 9, 2025
d360a71
Create README.md
mgvv Oct 9, 2025
6e6dde4
Update README.md
mgvv Oct 9, 2025
60ad2ca
Add script to find SAP* user parameters in profiles
mgvv Oct 29, 2025
be3557c
Add SSH setup script for user mgveliz
mgvv Nov 18, 2025
4ff4949
Create README.md for SSH Key Setup Script
mgvv Nov 18, 2025
9a0c26c
Add saprouter_manager.sh for SAProuter management
mgvv Nov 20, 2025
1244c86
Create README for SAProuter management script
mgvv Nov 20, 2025
bba2634
Add newline at end of saprouter_manager.sh
mgvv Nov 20, 2025
53cc478
Change SSH directory ownership to user group
mgvv Nov 21, 2025
9756739
Add smart_backup.sh for backup and restore functionality
mgvv Nov 21, 2025
1ddbabd
Add README for Smart Backup & Restore Tool
mgvv Nov 21, 2025
312a4e5
Enhance README with usage and installation details
mgvv Nov 21, 2025
698fcb5
Add PowerShell script to find largest files and folders
mgvv Nov 28, 2025
ce39fc1
Add README for PowerShell script to find largest files
mgvv Nov 28, 2025
4484f3d
Add sapinst_run.sh for sapinst execution with config
mgvv Dec 5, 2025
8725fdf
Add sapinst.ps1 script for SAP installation
mgvv Dec 12, 2025
7e095ea
Add PowerShell script to find specified processes
mgvv Dec 13, 2025
3f371df
Add script to set static IP using nmcli
mgvv Feb 24, 2026
45b2dc4
Create README for static IPv4 configuration script
mgvv Feb 24, 2026
a65f00e
Enhance README with usage and configuration details
mgvv Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions SysInfoProject/BACKUP_Things/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
```bash
cat << 'EOF' > README.md
# Smart Backup & Restore Tool

A versatile, hybrid Bash script for Linux that handles directory backups and restorations. It supports both a user-friendly **Interactive Menu** for manual use and a **Command Line Interface (CLI)** for automation and cron jobs.

## 🚀 Features

* **Hybrid Modes:** Use the interactive menu (`-i`) or command-line flags.
* **Multiple Formats:** Support for `.tar.gz` (Standard), `.tar.bz2` (High Compression), and `.zip` (Windows compatible).
* **Path Flexibility:** Choose between keeping the directory structure or a "Flat" backup (contents only).
* **Smart Restore:** Auto-detects the archive format during restoration—no need to specify the file type manually.
* **Safe:** Checks for required dependencies (`zip`, `unzip`) before attempting operations.

## 📋 Prerequisites

The script uses standard Linux tools. For `.zip` support, ensure you have `zip` and `unzip` installed:

\`\`\`bash
# Ubuntu/Debian
sudo apt install zip unzip

# RHEL/CentOS
sudo yum install zip unzip
\`\`\`

## ⚙️ Installation

1. Download or create the script file:
\`\`\`bash
nano smart_backup.sh
\`\`\`
2. Paste the script code and save.
3. Make the script executable:
\`\`\`bash
chmod +x smart_backup.sh
\`\`\`

## 📖 Usage

Running the script without arguments displays the help menu:

\`\`\`bash
./smart_backup.sh
\`\`\`

### 1. Interactive Mode
Best for manual, ad-hoc backups. This launches a text-based menu wizard.

\`\`\`bash
./smart_backup.sh -i
\`\`\`

### 2. Backup via CLI
Best for scripts and automation.

**Syntax:**
\`\`\`bash
./smart_backup.sh -b -s <SOURCE> -d <DESTINATION> [OPTIONS]
\`\`\`

**Examples:**

* **Standard Backup (keeps folder name):**
\`\`\`bash
./smart_backup.sh -b -s /var/www/html -d /backups
\`\`\`
* **Backup with specific format (bzip2):**
\`\`\`bash
./smart_backup.sh -b -s /home/user/docs -d /backups -t bz2
\`\`\`
* **"Flat" Backup (contents only, useful for dumping files directly):**
\`\`\`bash
./smart_backup.sh -b -s /var/log -d /tmp/logs -flat
\`\`\`

### 3. Restore via CLI

**Syntax:**
\`\`\`bash
./smart_backup.sh -r -f <BACKUP_FILE> -d <DESTINATION>
\`\`\`

**Example:**
\`\`\`bash
./smart_backup.sh -r -f /backups/html_20231010.tar.gz -d /var/www
\`\`\`

---

## 🚩 Argument Reference

| Flag | Argument | Description |
| :--- | :--- | :--- |
| **-i** | None | Enter **Interactive Mode**. |
| **-b** | None | Trigger **Backup Mode**. Requires \`-s\` and \`-d\`. |
| **-r** | None | Trigger **Restore Mode**. Requires \`-f\`. |
| **-s** | \`<path>\` | **Source** directory to backup. |
| **-d** | \`<path>\` | **Destination** directory (for saving backup or unpacking restore). |
| **-f** | \`<file>\` | **File** path of the archive to restore. |
| **-t** | \`<type>\` | Compression type: \`gz\` (default), \`bz2\`, or \`zip\`. |
| **-flat**| None | **Flat Mode**: Backs up files inside the folder, not the folder itself. |
| **-h** | None | Show help/usage message. |

## 🤖 Automation (Cron Job Example)

To run a backup every day at 3:00 AM using this script:

1. Open crontab: \`crontab -e\`
2. Add the following line:

\`\`\`cron
0 3 * * * /path/to/smart_backup.sh -b -s /home/user/data -d /mnt/backups -t gz
\`\`\`
EOF
262 changes: 262 additions & 0 deletions SysInfoProject/BACKUP_Things/smart_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
#!/bin/bash

# ==========================================
# Script Name: smart_backup.sh
# Description: Backup/Restore tool. Supports Interactive (-i) and CLI modes.
# ==========================================

# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# --- 1. Usage / Help Function ---
usage() {
echo -e "${BLUE}Usage: $0 [MODE] [OPTIONS]${NC}"
echo ""
echo -e "${YELLOW}MODES:${NC}"
echo " (No arguments) Show this help message"
echo " -i Enter Interactive Menu Mode"
echo " -b Run Backup (requires -s, -d)"
echo " -r Run Restore (requires -f)"
echo ""
echo -e "${YELLOW}BACKUP OPTIONS:${NC}"
echo " -s <path> Source directory to backup"
echo " -d <path> Destination directory for the archive"
echo " -t <type> Format: 'gz' (default), 'bz2', or 'zip'"
echo " -flat Save files directly (flat) instead of keeping directory structure"
echo ""
echo -e "${YELLOW}RESTORE OPTIONS:${NC}"
echo " -f <file> Full path to the backup file to restore"
echo " -d <path> Destination to unpack (default: current dir)"
echo ""
echo -e "${YELLOW}EXAMPLES:${NC}"
echo " Interactive: $0 -i"
echo " Backup (std): $0 -b -s /var/www -d /backups -t gz"
echo " Backup (flat): $0 -b -s /var/logs -d . -flat"
echo " Restore: $0 -r -f /backups/site.tar.gz -d /var/www"
exit 1
}

check_dependency() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}Error: '$1' is not installed.${NC}"
exit 1
fi
}

# --- 2. Core Logic Functions ---

core_backup() {
local SRC=$1
local DEST=$2
local FMT=$3
local FLAT=$4

# Validations
SRC=${SRC%/}
DEST=${DEST%/}

if [ -z "$SRC" ] || [ -z "$DEST" ]; then
echo -e "${RED}Error: Source (-s) and Destination (-d) are required.${NC}"
exit 1
fi
if [ ! -d "$SRC" ]; then
echo -e "${RED}Error: Source directory '$SRC' does not exist.${NC}"
exit 1
fi
mkdir -p "$DEST"

# Filename Setup
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
BASE_NAME=$(basename "$SRC")
BACKUP_NAME="${BASE_NAME}_${TIMESTAMP}"

# Path Strategy
if [ "$FLAT" == "true" ]; then
# Go inside, grab contents (spills out when unpacked)
cd "$SRC" || exit
TARGET="."
else
# Go to parent, grab folder name (creates folder when unpacked)
PARENT_DIR=$(dirname "$SRC")
TARGET=$(basename "$SRC")
cd "$PARENT_DIR" || exit
fi

echo -e "${BLUE}Backing up '$SRC' to '$DEST'...${NC}"

case $FMT in
gz|tar.gz)
tar -czf "${DEST}/${BACKUP_NAME}.tar.gz" $TARGET
FINAL_FILE="${DEST}/${BACKUP_NAME}.tar.gz"
;;
bz2|tar.bz2)
tar -cjf "${DEST}/${BACKUP_NAME}.tar.bz2" $TARGET
FINAL_FILE="${DEST}/${BACKUP_NAME}.tar.bz2"
;;
zip)
check_dependency "zip"
zip -r "${DEST}/${BACKUP_NAME}.zip" $TARGET
FINAL_FILE="${DEST}/${BACKUP_NAME}.zip"
;;
*)
# Default to GZ if unknown
tar -czf "${DEST}/${BACKUP_NAME}.tar.gz" $TARGET
FINAL_FILE="${DEST}/${BACKUP_NAME}.tar.gz"
;;
esac

if [ $? -eq 0 ]; then
echo -e "${GREEN}Success: $FINAL_FILE${NC}"
else
echo -e "${RED}Backup Failed.${NC}"
fi
}

core_restore() {
local FILE=$1
local DEST=$2

if [ -z "$FILE" ]; then
echo -e "${RED}Error: Backup file (-f) is required.${NC}"
exit 1
fi
if [ ! -f "$FILE" ]; then
echo -e "${RED}Error: File '$FILE' not found.${NC}"
exit 1
fi

# Default dest to current dir if empty
DEST=${DEST:-.}
mkdir -p "$DEST"

echo -e "${BLUE}Restoring '$FILE' to '$DEST'...${NC}"

if [[ "$FILE" == *.tar.gz || "$FILE" == *.tgz ]]; then
tar -xzf "$FILE" -C "$DEST"
elif [[ "$FILE" == *.tar.bz2 ]]; then
tar -xjf "$FILE" -C "$DEST"
elif [[ "$FILE" == *.zip ]]; then
check_dependency "unzip"
unzip "$FILE" -d "$DEST"
else
echo -e "${RED}Unknown format. Cannot extract.${NC}"
exit 1
fi

echo -e "${GREEN}Restore Complete.${NC}"
}

# --- 3. Interactive Wrapper ---
run_interactive() {
while true; do
clear
echo -e "${BLUE}=== INTERACTIVE BACKUP TOOL ===${NC}"
echo "1) Create Backup"
echo "2) Restore Backup"
echo "3) Exit"
read -p "Choice: " OPT

case $OPT in
1)
read -p "Source Folder: " I_SRC
read -p "Dest Folder: " I_DEST
echo "Format: 1) gz 2) bz2 3) zip"
read -p "Select [1-3]: " F_OPT
case $F_OPT in
1) I_FMT="gz" ;;
2) I_FMT="bz2" ;;
3) I_FMT="zip" ;;
*) I_FMT="gz" ;;
esac

echo "Structure: 1) Keep Folder Name 2) Flat (Content Only)"
read -p "Select [1-2]: " S_OPT
if [ "$S_OPT" == "2" ]; then I_FLAT="true"; else I_FLAT="false"; fi

core_backup "$I_SRC" "$I_DEST" "$I_FMT" "$I_FLAT"
;;
2)
read -p "Backup File Path: " I_FILE
read -p "Restore To (Enter for current): " I_DEST
core_restore "$I_FILE" "$I_DEST"
;;
3) exit 0 ;;
*) echo "Invalid" ;;
esac
echo "Press Enter..."
read
done
}

# --- 4. Main Execution & Argument Parsing ---

# If no arguments provided, show Usage
if [ $# -eq 0 ]; then
usage
fi

MODE=""
SRC=""
DEST=""
FILE=""
FMT="gz"
FLAT="false"

# Parse Arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-i|--interactive)
run_interactive
exit 0
;;
-b|--backup)
MODE="backup"
shift
;;
-r|--restore)
MODE="restore"
shift
;;
-s|--source)
SRC="$2"
shift; shift
;;
-d|--dest)
DEST="$2"
shift; shift
;;
-f|--file)
FILE="$2"
shift; shift
;;
-t|--type)
FMT="$2"
shift; shift
;;
-flat)
FLAT="true"
shift
;;
-h|--help)
usage
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
usage
;;
esac
done

# Execute based on mode
if [ "$MODE" == "backup" ]; then
core_backup "$SRC" "$DEST" "$FMT" "$FLAT"
elif [ "$MODE" == "restore" ]; then
core_restore "$FILE" "$DEST"
else
usage
fi
Loading