wiki.ipfire.org

The community-maintained documentation platform of IPFire

User Tools

Site Tools


optimization:usb-harddisk:start

Automatic backup of data from IPFire to an external USB-harddisk

IPFire can be set up to generate an automatic rsync backup (synchronization) on connection of a dedicated USB hard drive to the USB port. Data to be backed up is located on a local disk. The target file system is NTFS.

This process requires the Addon rsync. Please install it before proceeding.

  • First, /etc/udev/rules.d/23-usb.rules is extended by adding the entry:
/etc/udev/rules.d/23-usb.rules
ACTION=="add", SUBSYSTEMS=="usb", KERNEL=="sd?1", RUN+="/bin/usb_mount_wrapper.sh"
  • Create a directory /mnt/usb-backup
  • Create a Bash Script /bin/usb_mount_wrapper.sh with the following content
  • Create a Bash Script /bin/usb_mount.sh with the following content:
/bin/usb_mount_wrapper.sh
#!/bin/bash
 
/bin/usb_mount.sh &
 
exit 0
/bin/usb_mount.sh
#!/bin/bash
export PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/local/bin:
 
function log() {
echo "$@"
logger -t backup "#### $@ ####"
}
 
 
SOURCE="***your source***"
DEST="/mnt/usb-backup"
date=$(date +%Y%B%d)
 
log ".....Specialmount NTFS Label Backup......"''
 
mount.ntfs-3g  /dev/disk/by-label/usb-backup /mnt/usb-backup
 
 
log ".......start Backup............."
 
rsync -arlDuv --delete $SOURCE $DEST --log-file=$DEST/$date.txt
 
log ".......Backup done.............."
 
log ".......umount usb-hdd..........."
 
umount /mnt/usb-backup

Before the first test you must reboot the IPFire, format the USB drive as NTFS and you have to label it “usb-backup”. By labeling the drive, you prevent other connected USB hard drives being accidentally overwritten.

To check the backup performed a log file is generated by rsync, which is stored with the current date as a text file on the target USB drive.

optimization/usb-harddisk/start.txt · Last modified: 2018/11/15 02:11 by Jon