SOLVED automated copy of new folder contents

Joined
Jan 27, 2020
Messages
577
Hello,

I'm looking for an automated solution to copy new files from

mnt/tank/dataset_source/source_folder

to

mnt/tank/dataset_target/target_folder

something like cp -R -n but automated and periodically, i.e. per cron.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
Sounds like an rsync task... (perhaps with remote host name of localhost)
 
Joined
Jan 27, 2020
Messages
577
Yeah, I've read some bits about rsync with localhost. I'd really like some first hand experience from someone who has done it before I try it myself.
 

hervon

Patron
Joined
Apr 23, 2012
Messages
353
Lot's of examples in the forums. Search either here or on google since those are freeBSD ZFS commands. . What worked for me was zfs send receive commands.
 
Joined
Jan 27, 2020
Messages
577
As I understand it, zfs send is snapshot based and goes down to the dataset level not the folder level.
Can you give an example of zfs send / recieve for folder copy, much like cp -R?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
As I understand it, zfs send is snapshot based and goes down to the dataset level not the folder level.
Can you give an example of zfs send / recieve for folder copy, much like cp -R?
You are correct and therefore an example cannot be given. zfs send is a block-level copy.
rsync works great. Just create a task through the UI ...

Patrick
 
Joined
Jan 27, 2020
Messages
577
Just to confirm what @Patrick M. Hausen and @sretalla suggested, going with rsync where the remote host is set to "localhost" works well.
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
Can confirm.

Rsync is exactly what you are looking for. Use rsync -a /mnt/pool1/source/ /mnt/pool2/destination/ to 1 way archive source to destination. The -a option is equal to -rlptgoD so it is made for archiving. If you want the directories to always stay equal, i.e. deletions from source are deleted from destination, then use the --delete option such as rsync -a --delete /mnt/pool1/source/ /mnt/pool2/destination/.

In order to schedule it, put the commands in a shell script such as backupscript.sh. You will have to chmod +x backupscript.sh to make it executable. Inside the script put this (replace the pool etc. with the right stuff - pay attention to the last / too - might be good to read the rsync man page):

Code:
#!/bin/sh

rsync -a --delete /mnt/pool1/source/ /mnt/pool2/destination/


Use the Cron Jobs task to schedule this at whatever interval you want. Some caution must be used to make sure that you do not schedule it to run again when it is already going... There are many different ways to protect against this. I personally use lock files but I am a simpleton.

Rsync is one of the most useful tools in FreeBSD. Enjoy!!

Cheers,
 
Top