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, 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:
    password BACKUP PASSWORD

    macdef backup
    put $1 $2
    put $1.md5 $2.md5

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/backup

  • The backup script itself is stored in /root/bin/ 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/

    # Name of the backup file

    # temporary location of the backup archive

    # full path to the backup

    # 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

    # old UMASK backup

    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=" enter the hostname of the backup server.

  • Give the script the correct rights:
    [root@host ~]# chmod 700 /root/bin/

  • You 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/
    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.

Restore backup file

You can, for example, copy the backup from the backup server back to your server and then unpack it as follows:
[root@host ~]# curl > backup.tar.gz

[root@host ~]# tar -xvf backup.tar.gz