Saving Data on a Backup Server (Linux)
This manual explains how to automatically back up and restore your data on a backup server. The shell script example below also explains how to use IONOS FTP Storage as a backup server.
Please adjust the backupXX.pureserver.info, BACKUP USERNAME and BACKUP PASSWORD accordingly.
Please Note
This backup method is not suitable for a complete backup of all data on your server!
Create backups with a shell script
Create the .netrc file as root. Set the rights for only root to be able to view and edit the file.
[root@host ~]# touch /root/.netrc
[root@host ~]# chmod 600 /root/.netrc
In /root/.netrc add the following entries:
machine backupXX.onlinehome-server.info
login BACKUP USERNAME
password BACKUP PASSWORD
macdef backup
put $1 $2
put $1.md5 $2.md5
quit
Please Note
The word quit in the last line must be followed by a blank line.
The backup archive will be saved on the server before the backup. This should be done in /home :
[root@host ~]# mkdir /home/backup
[root@host ~]# chmod 700 /home/backupThe backup script itself is stored in /root/bin/simple-backup.sh. Please create the /root/bin directory if it does not already exist.
[root@host ~]# mkdir /root/bin
Create the backup script and save it to /root/bin/simple-backup.sh.
#!/bin/sh
# Name of the backup file
BACKUP_FILE="backup.tar.gz"
# temporary location of the backup archive
BACKUP_TMP="/home/backup/"
# full path to the backup
BACKUP=${BACKUP_TMP}${BACKUP_FILE}
# directories to be backed up
# in this example these are the customer web sites and emails
BACKUP_DATA="/home/htdocs /var/spool/mail"
# hostname of the backup server
BACKUP_SERVER="backupXX.pureserver.info"
# old UMASK backup
UMASK=`umask`
umask 0077
tar --exclude=${BACKUP} -czf ${BACKUP} ${BACKUP_DATA} 2>/dev/null
md5sum ${BACKUP} > ${BACKUP}.md5
echo "\$ backup ${BACKUP} ${BACKUP_FILE}" | pftp ${BACKUP_SERVER} >/dev/null
rm -f ${BACKUP} ${BACKUP}.md5
umask ${UMASK}
In the line BACKUP_SERVER="backupXX.onlinehome-server.info enter the hostname of the backup server.Give the script the correct rights:
[root@host ~]# chmod 700 /root/bin/simple-backup.shYou can set up a cronjob to automate the backup. To do so, create the file /etc/cron.d/simple-backup then enter the cronjob for a daily backup in the following form:
MINUTE HOUR * * * root /root /root/bin/simple-backup.sh
For MINUTE (0-59) and HOUR (0-24) set the desired time for the backup.
Please Note
When the backup is saved on the FTP server, the last backup on the server is overwritten.