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.
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.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.