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:
First, create the /home/backups
directory if it doesn't already exist:
mkdir -p /home/backups
Use the date
command to generate a timestamp for the backup directories:
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
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"
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"
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"
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"
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
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"
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
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
- 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!
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/