This is the LAMP / LEMP environment backup guide in case you want or need to try my highload LEMP installation.
As a first thing we will setup a variable that will store current date and time. We will use year-month-day_hours-minutes-seconds format:
now=$(date +"%Y-%m-%d_%H-%M-%S")
Then we need to create a folder where Nginx configuration files will be stored:
mkdir /backup/$now/nginx/
We will repeat previous step for your PHP installation:
mkdir /backup/$now/php/
If you already have MySQL or MariaDB installed do this step too:
mkdir /backup/$now/mysql/
This is the main backup process, just copy files from one folder to another.
For Nginx:
cp -r /etc/nginx/ /backup/$now/nginx/
For PHP:
cp -r /etc/php/ /backup/$now/php/
For MySQL / MariaDB:
cp -r /etc/mysql/ /backup/$now/mysql/
Everything above can be also used in a bash script for any package you want. Just create backup.sh with the following text:
#!/usr/bin/env bash
now=$(date +"%Y-%m-%d_%H-%M-%S")
mkdir /backup/$now/nginx/
mkdir /backup/$now/php/
mkdir /backup/$now/php/
mkdir /backup/$now/mysql/
cp -r /etc/nginx/ /backup/$now/nginx/
cp -r /etc/php/ /backup/$now/php/
cp -r /etc/mysql/ /backup/$now/mysql/
Make it executable:
chmod +x backup.sh
And run from the current directory:
./backup.sh