It is good to have automatic backups of critical servers. An easy way to make these backups is with a utility called rsync, but if you have to back up to a server that only supports FTP, here's a different approach.
Step-by-step guide
Some commands may require root permission, so log in as a standard user and use sudo.
Install lftp
yum install lftp
Create the backup script
Create the new file
You can save the file anywhere you like, it doesn't have to be in the example location we are using here.
nano /home/admin/Documents/backup.sh
Insert the script contents into the file
#!/bin/bash # Backs up files to remote FTP server HOST='server.example.com' USER='username' PASS='password' TARGETFOLDER='/target' SOURCEFOLDER='/source' lftp -f " open $HOST user $USER $PASS lcd $SOURCEFOLDER mirror --reverse --delete --verbose $SOURCEFOLDER $TARGETFOLDER bye "
- Replace 'server.example.com' with the IP or FQDN of the server to the FTP server where you will be sending files.
- Fill in the FTP username and password next.
- Replace '/target' with the location on the FTP server where you want the files sent.
- Replace '/source' with the location on the local machine where the files are that you want backed up.
- Don't change anything below the source folder line.
- Save the file.
Make the file executable
chmod +x /home/admin/Documents/backup.sh
Add the file to cron to make it execute automatically on a schedule.
The example below will execute every day at 2:00 AM.
0 2 * * * /home/admin/Documents/backup.sh
You can run the script manually to verify that it works.
sh /home/admin/Documents/backup.sh
- That's it! Everything should be all set.
Related articles