Since you’re running WordPress on AWS EC2 with Ubuntu, Nginx, PHP, and MySQL/MariaDB, I recommend implementing two backup methods:
- WordPress Full Backup: Back up WordPress files and the MySQL database.
- AWS EC2 Snapshot: Back up the EC2 EBS volume for disaster recovery.
For a more reliable solution, automate daily WordPress backups and store them in Amazon S3.

1. Backup Architecture
AWS EC2 (Ubuntu)
│
├── Nginx
├── PHP-FPM
├── WordPress
│ └── /var/www/vti
│ ├── wp-admin/
│ ├── wp-content/
│ ├── wp-includes/
│ └── wp-config.php
│
└── MySQL / MariaDB
└── WordPress Database
│
▼
Backup Script
│
├── WordPress Files (.tar.gz)
├── Database (.sql.gz)
└── Nginx Configuration (.tar.gz)
│
▼
Amazon S3
│
▼
Backup Retention
7–30 Days
Important: A complete WordPress backup requires both the database and website files. Backing up only /var/www/vti does not back up your MySQL database. WordPress Developer Resources
2. Method 1 — Manual WordPress Backup
Step 1: Connect to EC2
From your Mac terminal:
ssh -i your-key.pem ubuntu@YOUR_EC2_PUBLIC_IP
Step 2: Check WordPress directory
Your previous WordPress installation used:
/var/www/vti
Verify:
ls -lah /var/www/vti
Expected files:
wp-admin/
wp-content/
wp-includes/
wp-config.php
wp-login.php
wp-settings.php
index.php
Step 3: Create backup directory
sudo mkdir -p /var/backups/wordpress
sudo chmod 700 /var/backups/wordpress
Step 4: Backup WordPress files
Execute:
sudo tar -czpf \
/var/backups/wordpress/wordpress-files-$(date +%F).tar.gz \
-C /var/www vti
This creates:
/var/backups/wordpress/
└── wordpress-files-2026-10-08.tar.gz
This archive includes WordPress plugins, themes, uploaded images, and configuration files.
Step 5: Find WordPress database information
Execute:
sudo grep -E "DB_NAME|DB_USER|DB_HOST" \
/var/www/vti/wp-config.php
Example:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_HOST', 'localhost');
Record the database name and username.
Avoid displaying or sharing your database password unnecessarily.
Step 6: Backup MySQL database
If your WordPress database is named wordpress:
sudo mysqldump \
--single-transaction \
--quick \
--no-tablespaces \
wordpress | gzip > wordpress-db.sql.gz
On Ubuntu installations where the database root account uses socket authentication, sudo mysqldump may work without a password.
Recommended command with a permanent backup location:
sudo bash -o pipefail -c '
mysqldump \
--single-transaction \
--quick \
--no-tablespaces \
wordpress | gzip > \
/var/backups/wordpress/wordpress-db-$(date +%F).sql.gz
'
Replace wordpress with your actual database name.
For MariaDB installations, use mariadb-dump if mysqldump is unavailable.
Note: --single-transaction provides a consistent dump for transactional tables such as InnoDB, provided no conflicting schema changes occur during the backup.
Step 7: Backup Nginx configuration
Because your server uses Nginx, back up its configuration:
sudo tar -czpf \
/var/backups/wordpress/nginx-config-$(date +%F).tar.gz \
-C /etc nginx
If your site uses SSL certificates, also securely back up the relevant certificate and key configuration, such as /etc/letsencrypt, when applicable.
Step 8: Verify backups
sudo ls -lh /var/backups/wordpress/
Expected output:
wordpress-files-2026-10-08.tar.gz
wordpress-db-2026-10-08.sql.gz
nginx-config-2026-10-08.tar.gz
Verify archive integrity:
sudo tar -tzf \
/var/backups/wordpress/wordpress-files-$(date +%F).tar.gz \
> /dev/null
sudo gzip -t \
/var/backups/wordpress/wordpress-db-$(date +%F).sql.gz
A successful integrity check does not guarantee a successful restore. Periodically test restoration on a separate EC2 instance.
3. Method 2 — Backup Entire EC2 with EBS Snapshot
This method protects the EC2 server’s EBS volume, including the OS and locally stored application data.
Step 1: Open AWS Console
Navigate to:
AWS Console → EC2 → Elastic Block Store → Volumes
Step 2: Select your EC2 volume
Find the EBS volume associated with your WordPress EC2 instance.
Step 3: Create snapshot
Select:
Actions → Create snapshot
Example description:
WordPress-EC2-Backup-2026-10-08
Step 4: Verify snapshot
Navigate to:
EC2 → Elastic Block Store → Snapshots
Wait until its status becomes:
Completed
AWS supports EBS snapshots for volume recovery and automated backup through AWS Backup or Amazon Data Lifecycle Manager. AWS Documentation
Important: A live EBS snapshot does not automatically guarantee application-level database consistency. For production WordPress, use database-aware backups as well. If your database runs on Amazon RDS, configure RDS backups separately.
4. Method 3 — Automatically Backup WordPress to Amazon S3
This is my recommended solution for your EC2 WordPress website.
We will configure:
- Daily automatic backups at 2:00 AM.
- Backup WordPress files and database.
- Upload backups to Amazon S3.
- Retain backups for 30 days using an S3 Lifecycle rule.
- Support restoration to the same or a new EC2 instance.
Step 1: Create an S3 bucket
Open:
AWS Console → S3 → Create bucket
Example:
Bucket Name: hoacatyen-wordpress-backup
Region: ap-southeast-1 (Singapore)
Bucket names must be globally unique. Substitute another name if this one is unavailable.
Recommended settings:
| Setting | Value |
|---|---|
| Bucket type | General purpose |
| Block Public Access | Enabled |
| Encryption | SSE-S3 or SSE-KMS |
| Versioning | Optional |
| Lifecycle | 30 days |
| Region | Singapore |
Because WordPress backups contain database records and potentially credentials, keep the bucket private.
Step 2: Configure EC2 permissions
Use an IAM Role instead of storing AWS access keys on the server.
In AWS Console:
- Open IAM → Roles.
- Create a role for EC2.
- Attach an S3 policy with access to the backup bucket.
- Open EC2 → Instances.
- Select your WordPress instance.
- Choose Actions → Security → Modify IAM role.
- Attach the new role.
Example IAM permissions for uploading and restoring backups:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::hoacatyen-wordpress-backup"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
"Resource": "arn:aws:s3:::hoacatyen-wordpress-backup/*"
}
]
}
This example assumes SSE-S3 encryption. SSE-KMS requires appropriate KMS key permissions.
Step 3: Install AWS CLI
Check whether AWS CLI is installed:
aws --version
If it is missing, install AWS CLI v2 using the official AWS installer appropriate for your EC2 instance’s CPU architecture.
Verify the IAM role credentials:
aws sts get-caller-identity
You should see your AWS account information and the assumed IAM role.
Step 4: Create an automatic backup script
Create a script:
sudo nano /usr/local/sbin/wordpress-backup.sh
Paste:
#!/bin/bash
set -Eeuo pipefail
umask 077
# Configuration
SITE_DIR="/var/www/vti"
BACKUP_DIR="/var/backups/wordpress"
BUCKET="hoacatyen-wordpress-backup"
DB_NAME="wordpress"
DATE=$(date +%Y-%m-%d_%H-%M-%S)
WORK_DIR="${BACKUP_DIR}/${DATE}"
mkdir -p "$WORK_DIR"
# Remove incomplete local backup if script fails
trap 'rm -rf "$WORK_DIR"' ERR
echo "Starting WordPress backup: $DATE"
# Backup database
echo "Backing up database..."
mariadb-dump \
--single-transaction \
--quick \
--no-tablespaces \
"$DB_NAME" | gzip > "$WORK_DIR/database.sql.gz"
gzip -t "$WORK_DIR/database.sql.gz"
# Backup WordPress files
echo "Backing up WordPress files..."
tar -czpf \
"$WORK_DIR/wordpress-files.tar.gz" \
-C "$(dirname "$SITE_DIR")" \
"$(basename "$SITE_DIR")"
# Backup Nginx configuration
echo "Backing up Nginx..."
tar -czpf \
"$WORK_DIR/nginx-config.tar.gz" \
-C /etc nginx
# Verify archives
tar -tzf "$WORK_DIR/wordpress-files.tar.gz" > /dev/null
tar -tzf "$WORK_DIR/nginx-config.tar.gz" > /dev/null
# Upload backups to S3
echo "Uploading to S3..."
aws s3 cp \
"$WORK_DIR/" \
"s3://${BUCKET}/wordpress/${DATE}/" \
--recursive \
--only-show-errors
echo "Upload completed."
# Delete local backups older than 7 days
find "$BACKUP_DIR" \
-mindepth 1 \
-maxdepth 1 \
-type d \
-mtime +6 \
-exec rm -rf -- {} +
echo "WordPress backup completed successfully: $DATE"
Before running: Change DB_NAME to match your WordPress database. The script assumes MariaDB is installed locally and the root account can access it through Unix socket authentication.
If your server uses MySQL, replace mariadb-dump with mysqldump.
The script uses a separate timestamped S3 folder for each backup, avoiding accidental overwrites. AWS supports this type of recursive upload using aws s3 cp. AWS Documentation
For your production implementation, I would also include SSL configurations and adjust database connection handling if your WordPress database is external.
Step 5: Configure permissions
sudo chown root:root /usr/local/sbin/wordpress-backup.sh
sudo chmod 700 /usr/local/sbin/wordpress-backup.sh
Step 6: Test the script
sudo /usr/local/sbin/wordpress-backup.sh
Expected output:
Starting WordPress backup: 2026-10-08_08-30-00
Backing up database...
Backing up WordPress files...
Backing up Nginx...
Uploading to S3...
Upload completed.
WordPress backup completed successfully.
Verify the S3 objects:
aws s3 ls \
s3://hoacatyen-wordpress-backup/wordpress/ \
--recursive
Use sudo aws s3 ls if you need to run the command in the same environment as the root-owned backup script.
Step 7: Schedule daily backups
Edit the root crontab:
sudo crontab -e
Add:
0 2 * * * /usr/local/sbin/wordpress-backup.sh >> /var/log/wordpress-backup.log 2>&1
This executes every day at 2:00 AM according to the EC2 instance’s timezone.
Check the timezone:
timedatectl
If your EC2 uses UTC, 2:00 AM UTC corresponds to 9:00 AM in Vietnam.
To run backups at 2:00 AM Vietnam time, you can use:
CRON_TZ=Asia/Ho_Chi_Minh
0 2 * * * /usr/local/sbin/wordpress-backup.sh >> /var/log/wordpress-backup.log 2>&1
However, CRON_TZ is not supported by every cron implementation. On Ubuntu, a portable approach is to schedule the job at 19:00 UTC, which corresponds to 02:00 the following day in Vietnam, if the EC2 timezone remains UTC.
Step 8: Configure S3 backup retention
In AWS Console:
S3 → Bucket → Management → Lifecycle rules
Create a lifecycle rule:
Rule Name: wordpress-backup-retention
Prefix: wordpress/
Expire current objects after: 30 days
This removes old backups automatically.
If bucket versioning is enabled, configure noncurrent version expiration as well so previous object versions do not accumulate indefinitely.
5. How to Restore WordPress from Backup
Suppose your EC2 instance fails and you need to restore WordPress to a new Ubuntu server.
Step 1: Download backup from S3
sudo mkdir -p /var/backups/wordpress-restore
Download a particular backup:
sudo aws s3 cp \
s3://hoacatyen-wordpress-backup/wordpress/2026-10-08_08-30-00/ \
/var/backups/wordpress-restore/ \
--recursive
Replace the timestamp with the backup you want to restore.
Step 2: Restore WordPress files
On a server where the required web stack is already installed:
sudo tar -xzpf \
/var/backups/wordpress-restore/wordpress-files.tar.gz \
-C /var/www/
Verify:
ls -lah /var/www/vti
Step 3: Restore the database
First, create the database and database user if they don’t already exist. Ensure their credentials match wp-config.php.
Then import the SQL backup:
gunzip -c \
/var/backups/wordpress-restore/database.sql.gz \
| sudo mariadb wordpress
Warning: Importing a backup into an existing database can overwrite its data. Restore into a separate test database first when possible.
Step 4: Restore permissions
On a typical Ubuntu Nginx installation:
sudo chown -R www-data:www-data /var/www/vti
Then set appropriate directory and file permissions:
sudo find /var/www/vti -type d -exec chmod 755 {} \;
sudo find /var/www/vti -type f -exec chmod 644 {} \;
sudo chmod 640 /var/www/vti/wp-config.php
Depending on your PHP-FPM user and deployment configuration, ownership may need to differ.
Step 5: Verify Nginx
After restoring the required Nginx configuration and SSL certificates:
sudo nginx -t
If successful:
sudo systemctl reload nginx
Test the WordPress website and confirm that posts, media, plugins, and administrator access work correctly.
6. Recommended Backup Strategy
For your WordPress website running on AWS EC2, I recommend:
| Backup Type | Frequency | Retention | Storage |
|---|---|---|---|
| WordPress database | Daily | 30 days | Amazon S3 |
| WordPress files | Daily | 30 days | Amazon S3 |
| Nginx configuration | Daily | 30 days | Amazon S3 |
| EBS snapshot | Weekly | 4 weeks | AWS EBS Snapshots |
| Pre-upgrade backup | Before each update | As needed | Amazon S3 |
| Restore testing | Monthly | — | Test EC2 instance |
For production, also configure backup failure notifications, S3 encryption, restricted IAM permissions, and protection against accidental deletion.
My recommendation
For your current WordPress demo website on EC2, use:
Daily WordPress backup → Amazon S3 + Weekly EBS snapshots.
This provides two recovery options:
- WordPress recovery: Restore your website onto a working EC2 instance.
- Server disaster recovery: Restore an EBS volume from a snapshot and recover the EC2 environment.
One important distinction: an EBS snapshot is not a complete record of the EC2 instance’s networking, security groups, IAM role, or other AWS configuration.
One question: Would you like to configure automatic WordPress backups from EC2 to S3 with email notifications when backups succeed or fail? I can provide the complete Ubuntu shell script and configuration tailored to your /var/www/vti installation.