Operations 4 min read

How to Schedule Automatic Backups for PHP Websites on CentOS

This guide explains three practical methods—using crontab, rsync, and mysqldump—to set up scheduled backups of PHP website files and databases on a CentOS server, ensuring data protection through automated daily or periodic tasks.

php Courses
php Courses
php Courses
How to Schedule Automatic Backups for PHP Websites on CentOS

CentOS is a popular Linux distribution widely used for servers, and PHP is a common server‑side scripting language for many websites. Regular automated backups are essential to protect PHP site data on CentOS.

1. Use crontab for scheduled tasks – edit the crontab with crontab -e and add a line such as 0 0 * * * /path/to/backup-script.sh to run a backup script at midnight each day.

2. Use rsync for file backups – install rsync ( yum install rsync), create a backup directory, and write a script (e.g.,

#!/bin/bash
rsync -av --delete /path/to/website /path/to/backup/$(date +%Y-%m-%d)

) then make it executable ( chmod +x /path/to/backup-script.sh) and run it.

3. Use mysqldump for database backups – install MySQL utilities, create a backup folder, and create a script (e.g.,

#!/bin/bash
mysqldump -u username -p password database_name > /path/to/mysql_backup/$(date +%Y-%m-%d).sql

) replacing placeholders with real credentials, make it executable, and schedule it similarly.

Choose the method that fits your environment and schedule the tasks to ensure regular protection of website files and databases.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxPHPBackuprsyncCentOSmysqldumpcrontab
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.