Skip to main content

Backup to USB Drive

Introduction

For same applications it might be necessary to use an external drive without adding this drive to a ZPool. E.g. if you want to copy from or to an external device.

Setup / mounting

TrueNAS will not mount a drive automatically when plugged into an USB Port. This has to be done manually. In this example I will use an external drive from LaCie.

  1. Plug in the drive to any USB Port
  2. Figure out the name of the device. It can be seen in Storage --> Disks. It is usually the drive without pool.
  3. Enter
    lsblk -p | grep "disk\|part"
    It will show show the exact name of the partition you want to mount. Bildschirmfoto 2023-12-17 um 17.54.37.png
    In this case it is sdd2.
  4. Create a mountpoint
    sudo mkdir /mnt/LaCie
  5. Mount the device
    sudo mount /dev/sdd2 /mnt/LaCie
  6. add to fstab
    /dev/sdd2 /mnt/LaCie hfsplus rw,relatime,umask=22,uid=0,gid=0,nls=utf8 0 0

Create an rsync job

Create the file /root/rsync_exclude.txt with this content:

ix-applications
replika
.~tmp~
*/._*
*/.DocumentRevisions-V100/
*/.DS_Store
*/.fseventsd/
*/.Spotlight-V100/
*/.TemporaryItems/
*/.Trashes/
.@*
.*
@Recycle
*.@__thumb
sync.ffs_lock

All these files/directories will not be copied to the target drive. These items are created by MacOS and will automaticall re-created, when these objecst in the backup are used by MacOS.

The command for the rsync job looks like this:

rsync -av --delete --log-file="/var/log/rsyncd.LaCie.log" --no-perms --no-owner --exclude-from "/root/rsync_exclude.txt" /mnt/N4pool/ /mnt/LaCie/backup --no-perms

If you want to run it over the network:

rsync -av --delete --log-file="/var/log/rsyncd.LaCie.log" --no-perms --no-owner --exclude-from "/root/rsync_exclude.txt" rsync@nas04.simmy.ch:/mnt/N4pool/ /mnt/LaCie2/LaCie/backup 

/dev/sda2 /mnt/LaCie vfat rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro 0 0

/dev/sdb2 /mnt/LaCie vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0

Add to cron

Goto System settings --> Advanced -->Cron Jobs Add

Bildschirmfoto 2023-12-21 um 17.30.00.png

rsync documentation

Manually mount a USB drive in the Linux terminal

How To Use Rsync to Sync Local and Remote Directories