Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.
Resource icon

A script to run rclone on the FreeNAS server to backup NAS data to Backblaze B2 cloud storage. 1.0

A script to run rclone on the FreeNAS server to backup NAS data to Backblaze B2 cloud storage. Can easily be adapted for other cloud providers.

Script was adapted from the one posted in the FreeNAS community forums by Martin Aspeli:

Why? Freenas (v11.1 onwards) now supports rclone nativetly and also has GUI entries for Cloudsync, however there is no option to use additional parameters within the GUI, thus I have adapted a script to be run instead via a cron job.

The log file rclone produces is not user friendly, therefore this script will also create a more user friendly log (to use as the email body). This shows the stats, and a list of files Copied (new), Copied (replaced existing), and Deleted - as well as any errors/notices (see my github site for examples).

Note: The rclone config file saved via the CLI is different to the one used in the FreeNAS GUI, so its safe to update this configuration file via rclone config without affecting anything you have configured in the FreeNAS GUI.

There are two scripts, one called, which has been created by myself, and one called (obtained online, however unsure where from now).

Step 1
First off you need to configure rclone for Backblaze B2 as per:, and if encrypting your data with rclone you then need to configure as per:

Step 2
Download the two shell scripts from my github site.

Step 3
Save the two scripts within a dataset on your FreeNAS server.

Step 4
You now need to edit the script, to update as per your specific requirements:


Basically the default settings above will:

backup all data within your pool (/mnt/tank in my case).
store them in the root of your remote:bucket on Backblaze B2 (secret:/ in my case).
your email address, for backup results and log file.
the name and location of log file (no real need to change this).
for your first run I recommend this is set to NOTICE, as this will only report errors, otherwise the log file will get very large. Once you have completed your first backup, you can change this it INFO, which will let you know what files were backed-up or deleted.
the name and location of the formatted log file, used to form email body (no real need to change this).
set a minimal age of the file before it is backed, handy for ignoring files currently in use.
the amount of simultaneous transfer, Backblaze recommends a lot, so I have set at 16, but you can tweak this depending on your broadband connection.

You then want to tweak the command line which is executed:

rclone sync \
    --transfers ${transfers} \
    --fast-list \
    --copy-links \
    --min-age ${min_age} \
    --log-level ${log_level} \
    --log-file ${log_file} \
    --b2-hard-delete \
    --exclude "Thumbs.db" \
    --exclude "desktop.ini" \
    --exclude "AlbumArt*" \
    --exclude ".recycle/**" \
    --exclude ".windows" \
    --exclude "iocage/**" \
    ${src} ${dest}

Use recursive list if available, uses more memory but fewer Backblaze B2 Class C transactions (i.e. cheaper). Not supported by all cloud providers though.
Follow symlinks and copy the pointed to item. (delete this line if not wanted)
Permanently delete files on remote removal, otherwise hide files. This means no version control of files on Backblaze (saves space & thus costs). This is a Backblaze B2 specific command. (delete this line if not wanted)
These lines will exclude certain files and folders from being backed-up. (delete this if not wanted, or edit, or add additional lines as per your needs)

Finally, at the end of the script you need to edit the location of the script:

/mnt/tank/Sysadmin/scripts/ "${email}" "${email}" "${subject}" "$(cat $log_file_formatted)" "${log_file}"

In my case, this is at /mnt/tank/Sysadmin/scripts/.

Step 5
You now want to create a new cron job task via the FreeNAS GUI, remembering the command you want to run is the full path to the script, for example:


I recommend that for the first time you run this, that you do not enable the task. This is because the first run could take some time, many days if you have a few TB to backup. You do not want the server starting a new task while the old one is still running, as this will only confuse the backup process and slow down your server.

So, for your first time, just select the task and select Run Now, i.e.


Note: If the FreeNAS server reboots at any time during this first run, then you will need to restart the process by selecting Run Now again. This will re-scan the files and continue from where it last got to.

Step 6
Once the backup task has completed you should receive an email, along with a log file (of any errors encountered).

You can now edit the cron job and tick the Enabled box, so that the task will run automatically at the times you want. You may also want to edit the script to change the log-level to INFO at this stage.

I hope this helps?

  • Like
Reactions: Borre
First release
Last update
0.00 star(s) 0 ratings

More resources from Hazimil