Setting up File Backups on a Dedicated CentOS 8 Server

File backups are crucial for any server; data loss due to a failure can be devastating. Setting up backups on a CentOS 8 server is straightforward if you know a few basic commands and principles.

First, ensure the rsync package is installed on your server. This provides convenient file copying capabilities. Install it using this command:

sudo yum install rsync

After installing rsync, you can proceed with setting up the backup. Let’s create a script to copy files and save their archive.

vim backup_script.sh

This opens the Vim text editor. Enter the following script:

#!/bin/bash rsync -av --delete /path/to/source /path/to/destination/ tar czf /path/to/backup-$(date +%Y%m%d).tar.gz /path/to/destination/

In this script, the rsync command copies files from the specified source path /path/to/source to the destination folder /path/to/destination/, preserving the file structure. Then, the tar command creates an archive with the current date and compresses it to save disk space.

Save the script and make it executable using the command:

chmod +x backup_script.sh

Now, add this script to your crontab schedule for regular backups. Open crontab for editing:

crontab -e

Add the following line to the end of the file to run the script every night at 3 AM:

0 3 * * * /path/to/backup_script.sh

Save the changes and close the editor. Your file backups will now be automated nightly, ensuring data safety and security.

Remember to regularly check the backup process and server disk space to avoid data loss in case of failure. We hope this article helps you set up file backups on your CentOS 8 server.