Before starting the backup, confirm the FTP server software (commonly vsftpd
, ProFTPD
, or Pure-FTPd
) and key directories:
/var/ftp
for vsftpd
, /home/ftpuser
for local users)./etc/vsftpd/vsftpd.conf
for vsftpd
)./var/log/vsftpd.log
for vsftpd
).Stop the FTP service to ensure data consistency during backup:
sudo systemctl stop vsftpd # Replace with `proftpd` or `pure-ftpd` if using other software
Use the tar
command to package all critical files (data directory, configuration, logs) into a compressed archive with a timestamp:
sudo tar -czvf ftp_full_backup_$(date +%Y%m%d_%H%M%S).tar.gz \
/etc/vsftpd/vsftpd.conf \
/var/ftp/ \
/var/log/vsftpd.log
This creates a single file (e.g., ftp_full_backup_20251022_1430.tar.gz
) containing all essential data.
rsync
with the --link-dest
option to save space:sudo rsync -avz --link-dest=/backup/ftp_last_full /var/ftp/ /backup/ftp_incremental_$(date +%Y%m%d)
rsync
without --link-dest
:sudo rsync -avz /var/ftp/ /backup/ftp_differential_$(date +%Y%m%d)
Schedule regular backups using crontab
. For example, run a daily full backup at 2 AM:
sudo crontab -e
Add the following line (replace /path/to/backup_script.sh
with your script path):
0 2 * * * /bin/bash /path/to/backup_script.sh
The script should include steps for compression, timestamping, and remote storage (see 2.4 Remote Storage).
Transfer backups to a secure offsite location (e.g., cloud storage, remote server) using scp
or rsync
:
sudo scp /backup/ftp_full_backup_*.tar.gz user@remote_server:/remote/backup/path/
Or use rsync
for incremental sync:
sudo rsync -avz /backup/ftp_incremental_*.tar.gz user@remote_server:/remote/backup/path/
Prevent data corruption during recovery by stopping the service:
sudo systemctl stop vsftpd
sudo tar -xzvf ftp_full_backup_20251022_1430.tar.gz -C /
Copy the backed-up configuration file to its original location:
sudo cp /backup/ftp/vsftpd.conf /etc/vsftpd/
Restore log files if needed (note: logs may be overwritten by the service after restart):
sudo cp /backup/ftp/vsftpd.log /var/log/vsftpd.log
Ensure files and directories have correct permissions (data directory: 755
, files: 644
):
sudo find /var/ftp -type d -exec chmod 755 {} \;
sudo find /var/ftp -type f -exec chmod 644 {} \;
Bring the server back online:
sudo systemctl start vsftpd
cron
logs or backup software notifications to ensure jobs complete successfully.gpg
) and store them in a secure location (e.g., encrypted cloud storage).By following this strategy, you can protect your CentOS FTP server data from loss and ensure quick recovery in case of failures.