Skip to content

Latest commit

 

History

History
144 lines (109 loc) · 3.99 KB

backuping-routine-script.md

File metadata and controls

144 lines (109 loc) · 3.99 KB

To back up configuration files for nginx, MySQL, and other services (including /etc/ems) into a /home/backups directory with subdirectories named after each service and the current date and time, you can use the following commands:


1. Create the Backup Directory

First, create the /home/backups directory if it doesn't already exist:

mkdir -p /home/backups

2. Define the Backup Path with Date and Time

Use the date command to generate a timestamp for the backup directories:

TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")

3. Backup Nginx Configuration

Back up the Nginx configuration files (typically located in /etc/nginx):

mkdir -p "/home/backups/nginx_$TIMESTAMP"
cp -r /etc/nginx "/home/backups/nginx_$TIMESTAMP"

4. Backup MySQL Configuration

Back up the MySQL configuration files (typically located in /etc/mysql):

mkdir -p "/home/backups/mysql_$TIMESTAMP"
cp -r /etc/mysql "/home/backups/mysql_$TIMESTAMP"

5. Backup Other Services

If you have other services with configuration files in /etc, you can back them up similarly. For example, to back up /etc/ems:

mkdir -p "/home/backups/ems_$TIMESTAMP"
cp -r /etc/ems "/home/backups/ems_$TIMESTAMP"

6. Backup All Services in /etc (Optional)

If you want to back up all configuration files in /etc for all services:

mkdir -p "/home/backups/etc_$TIMESTAMP"
cp -r /etc "/home/backups/etc_$TIMESTAMP"

7. Verify the Backups

Check that the backups were created successfully:

ls -l /home/backups

You should see directories like:

/home/backups/nginx_2023-10-05_14-30-00
/home/backups/mysql_2023-10-05_14-30-00
/home/backups/ems_2023-10-05_14-30-00

8. (Optional) Compress the Backups

To save space, you can compress each backup directory into a .tar.gz file:

tar -czvf "/home/backups/nginx_$TIMESTAMP.tar.gz" -C "/home/backups/nginx_$TIMESTAMP" .
tar -czvf "/home/backups/mysql_$TIMESTAMP.tar.gz" -C "/home/backups/mysql_$TIMESTAMP" .
tar -czvf "/home/backups/ems_$TIMESTAMP.tar.gz" -C "/home/backups/ems_$TIMESTAMP" .

Then, remove the original directories to save space:

rm -rf "/home/backups/nginx_$TIMESTAMP" "/home/backups/mysql_$TIMESTAMP" "/home/backups/ems_$TIMESTAMP"

9. Full Script

Here’s the complete script to automate the backup process:

#!/bin/bash

# Create backup directory
mkdir -p /home/backups

# Generate timestamp
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")

# Backup Nginx
mkdir -p "/home/backups/nginx_$TIMESTAMP"
cp -r /etc/nginx "/home/backups/nginx_$TIMESTAMP"

# Backup MySQL
mkdir -p "/home/backups/mysql_$TIMESTAMP"
cp -r /etc/mysql "/home/backups/mysql_$TIMESTAMP"

# Backup /etc/ems
mkdir -p "/home/backups/ems_$TIMESTAMP"
cp -r /etc/ems "/home/backups/ems_$TIMESTAMP"

# (Optional) Compress backups
tar -czvf "/home/backups/nginx_$TIMESTAMP.tar.gz" -C "/home/backups/nginx_$TIMESTAMP" .
tar -czvf "/home/backups/mysql_$TIMESTAMP.tar.gz" -C "/home/backups/mysql_$TIMESTAMP" .
tar -czvf "/home/backups/ems_$TIMESTAMP.tar.gz" -C "/home/backups/ems_$TIMESTAMP" .

# (Optional) Remove uncompressed directories
rm -rf "/home/backups/nginx_$TIMESTAMP" "/home/backups/mysql_$TIMESTAMP" "/home/backups/ems_$TIMESTAMP"

# Verify backups
ls -l /home/backups

10. Run the Script

Save the script to a file, e.g., backup_configs.sh, make it executable, and run it:

chmod +x backup_configs.sh
./backup_configs.sh

Summary

  • Backups are stored in /home/backups with directories named after the service and timestamp.
  • You can optionally compress the backups to save space.
  • The script can be automated using cron for regular backups.

Let me know if you need further assistance!

curling a websocket connection:

 curl -v   -H "Connection: Upgrade"   -H "Upgrade: websocket"   -H "Sec-WebSocket-Version: 13"   -H "Sec-WebSocket-Key: $(openssl rand -base64 16)"   http://yout-server-addrs/your/path/