The FreeNAS server consists of three, 4TB drives in a ZFS filesystem which is similar to a raid 5 setup. This gives a total useable storage size of around 7TB and allows for redundancy with one drive able to fail and data still recoverable. I will go though some basic steps of how to use the share and set it to backup your home folder on linux.
- Make sure you have an account on the FreeNAS server
- I will be able to setup your account on the server if you’re in the research group
- Make sure you can connect to the server
- In our case the server has two IP addresses on the network
172.21.139.214
and172.21.139.168
- To check if you can connect:
- In our case the server has two IP addresses on the network
ping -c 3 172.21.139.214
- Now make sure you have the required packeges to mount network drives
- cifs or nfs should work but I will be using cifs for the tutorial. To change to nfs just replace
any part that says
cifs
withnfs
.
- cifs or nfs should work but I will be using cifs for the tutorial. To change to nfs just replace
any part that says
sudo apt-get install cifs-utils smbfs
- Make a credentials file in your home directory
- This file is going to store your username and password so we’re going to make sure it has the proper security so that it is not readable by everyone.
- Make a file called
.smbcredentials
in your home folder~/
. - Place this in the file replacing
name
with the username you setup on the FreeNAS server and****
with the password.
username=name
password=****
- Change the owner and permissions on the credentials file.
sudo chown root .smbcredentials
sudo chmod 600 .smbcredentials
- Now make a folder to mount the FreeNAS server to. Replace
username
with the username on your system. If you don’t know you can check it with thewhoami
command.
sudo mkdir /mnt/FreeNAS
sudo chown -R username:username /mnt/FreeNAS
- Find your user id and group id using the
id
command. In most cases if you were the first user on the system they both should be1000
but it’s still a good idea to check.
uid=1000(username) gid=1000(username) .....
- As the root user edit
/etc/fstab
and add this line to the end of the file. Make sure to replaceuser
with your username anduserid
andgroupid
with the id’s found in the pervious step.
//172.21.139.168/backups /mnt/FreeNAS cifs credentials=/home/user/.smbcredentials,isocharset=utf8,sec=ntml,uid=userid,gid=groupid 0 0 0
- Now check to see if eveything mounts correctly:
sudo mount -a
Now your computer should have the FreeNAS server mounted as a drive on your computer in the folder /mnt/FreeNAS
you
should be able to look into that directory and find a directory with your name where you can place anything you would
like to backup. The next step will be to setup an automatic backup using rsync.
- Create a file called
backup.sh
and place the following inside of it making sure to change theusername
andShareName
to your match your name.- At a minimum you should exclude
.ssh
and.smbcredentials
since these contain sensative information. - Make sure to add any other folders that may include sensative information.
- This storage is mainly for your personal files so it is advised to exclude any folder with large amounts of raw data which is backed up in other locations.
- At a minimum you should exclude
#!/bin/bash
rsync -av --exclude='.ssh' --exclude=".smbcredentials" --exclude='Downloads' --exclude='Desktop' /home/username /mnt/FreeNAS/ShareName
- You can then move this file to the proper location and create a cronjob so that the script runs every hour during the workday.
sudo mv backup.sh /usr/local/sbin/
crontab -e
- Add the following to the end of your crontab file.
0 8,9,10,11,12,13,14,15,16,17,18,19 * * * /usr/local/sbin/backup.sh
If all these steps worked then your computer should backup your home folder everyday of the week from 8am-7pm. You can change this by editing the time you added to your crontab file.