WordPress backup to Yandex Cloud: mysqldump, rclone, and Telegram notifications
Published on 2025-10-15
🎉 WordPress Backup to Yandex Cloud: mysqldump, rclone and Telegram Notifications
Running a site on WordPress is great, but data reliability and security are a priority. Regular backups protect the project from errors, attacks, and failures. In this guide we’ll look at how to create an automatic WordPress backup using:
mysqldump
— for the database,rclone
— for uploading to Yandex Cloud,curl
— for notifications in Telegram.
🛠️ Step 1. Creating a Local Backup
1.1 Checking WordPress Configuration
The wp-config.php
file is located in the site root (/var/www/ваш_сайт/wp-config.php
):
define('DB_NAME', 'ваш_db_name');
define('DB_USER', 'ваш_db_user');
define('DB_PASSWORD', 'ваш_db_password');
Write down the database connection parameters.
1.2 Backing Up Site Files
mkdir -p /home/backup/
cd /var/www/ваш_сайт/
tar -czf /home/backup/wp_files_$(date +%Y%m%d).tar.gz .
This produces an archive with themes, plugins, and media files.
1.3 Backing Up the Database
mysqldump -u ваш_db_user -pваш_db_password ваш_db_name | gzip > /home/backup/wp_db_$(date +%Y%m%d).sql.gz
To avoid storing the password in the command, create the file ~/.my.cnf
:
[mysqldump]
user=ваш_db_user
password=ваш_db_password
Permissions:
chmod 600 ~/.my.cnf
Now:
mysqldump ваш_db_name | gzip > /home/backup/wp_db_$(date +%Y%m%d).sql.gz
In /home/backup/
there will be two files:
wp_files_YYYYMMDD.tar.gz
and wp_db_YYYYMMDD.sql.gz
.
☁️ Step 2. Setting up Yandex Cloud and rclone
2.1 Installing rclone
sudo apt update && sudo apt install rclone -y
For other systems see rclone.org.
2.2 Obtaining Access Keys
Sign in to the Yandex Cloud Console.
Create a service account in IAM.
Create a static access key and note:
Access Key ID
Secret Access Key
Do not publish the keys.
2.3 Configuring rclone
rclone config
n
— create a new remote.Name:
yandex_storage
.Type:
S3
.Provider:
Amazon S3 Compliant Storage
.Enter:
access_key_id
: your keysecret_access_key
: your secretendpoint
:https://storage.yandexcloud.net
🚀 Step 3. Uploading the Backup to Yandex Cloud
Create a bucket, for example wp-backups-example
.
rclone copy /home/backup/ yandex_storage:wp-backups-example/ --log-file /home/backup/rclone.log
To automatically remove old archives enable Lifecycle Policy in the bucket settings (for example, delete files older than 30 days).
📬 Step 4. Telegram Notifications
4.1 Creating a Bot
In Telegram open
@BotFather
.Send
/newbot
.Get the token:
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
4.2 Obtaining the Chat ID
Send a message to the bot, then run:
curl -s "https://api.telegram.org/botВАШ_ТОКЕН/getUpdates"
Find "chat":{"id":...}
— this is your CHAT_ID
.
4.3 Test Message
curl -s -X POST "https://api.telegram.org/botВАШ_ТОКЕН/sendMessage" \
-d chat_id=ВАШ_CHAT_ID \
-d text="Тестовое сообщение"
⏱️ Step 5. Automation with Cron
Create the file /home/backup/daily_backup.sh
:
#!/bin/bash
SITE_DIR="/var/www/ваш_сайт/"
BACKUP_DIR="/home/backup/"
DB_NAME="ваш_db_name"
DB_USER="ваш_db_user"
DB_PASS="ваш_db_password"
RCLONE_REMOTE="yandex_storage"
BUCKET_NAME="wp-backups-example"
LOG_FILE="/home/backup/backup.log"
TELEGRAM_BOT_TOKEN="ВАШ_ТОКЕН"
TELEGRAM_CHAT_ID="ВАШ_CHAT_ID"
send_telegram() {
local message="$1"
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-d chat_id="${TELEGRAM_CHAT_ID}" \
-d text="${message}" >> "${LOG_FILE}" 2>&1
}
if [[ ! -d "$SITE_DIR" ]] || [[ ! -d "$BACKUP_DIR" ]]; then
echo "Ошибка: директория отсутствует" >> "$LOG_FILE"
send_telegram "Ошибка бэкапа: нет директории"
exit 1
fi
cd "$SITE_DIR" || { send_telegram "Ошибка перехода в директорию"; exit 1; }
tar -czf "${BACKUP_DIR}wp_files_$(date +%Y%m%d).tar.gz" . || { send_telegram "Ошибка архивации"; exit 1; }
mysqldump -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" | gzip > "${BACKUP_DIR}wp_db_$(date +%Y%m%d).sql.gz" || { send_telegram "Ошибка дампа БД"; exit 1; }
rclone copy "$BACKUP_DIR" "${RCLONE_REMOTE}:${BUCKET_NAME}/" --log-file "$LOG_FILE" || { send_telegram "Ошибка загрузки в облако"; exit 1; }
find "$BACKUP_DIR" -type f -mtime +7 -delete
send_telegram "✅ Бэкап успешно завершён: $(date)"
Make it executable:
chmod +x /home/backup/daily_backup.sh
Add the job to Cron:
crontab -e
0 3 * * * /home/backup/daily_backup.sh >> /home/backup/backup.log 2>&1
✅ Recommendations
- Test restores. Verify that backups actually work.
- Use Lifecycle Policy. Delete old backups.
- Telegram secrets. Store the token and chat_id in a secure file.
- For large sites: consider incremental backups or plugins like UpdraftPlus and Duplicator.
Congratulations — your WordPress is now protected by automatic backups in Yandex Cloud with notifications in Telegram.