NFS server with Lsyncd in Ubuntu
Make the attached volumes ready
Create folders
sudo mkdir /mnt/upload_disk1sudo mkdir /mnt/upload_disk2sudo mkdir /mnt/backup_disk1sudo mkdir /mnt/backup_disk2
Create partition
sudo fdisk /dev/nvme0n1sudo fdisk /dev/nvme1n1sudo fdisk /dev/nvme2n1sudo fdisk /dev/nvme3n1
Make filesystem
sudo mkfs.xfs /dev/nvme0n1p1sudo mkfs.xfs /dev/nvme1n1p1sudo mkfs.xfs /dev/nvme2n1p1sudo mkfs.xfs /dev/nvme3n1p1
Add fstab entry
sudo vim /etc/fstab
Add the following content
/dev/nvme0n1p1 /mnt/upload_disk1 xfs defaults,nofail 0 0
/dev/nvme3n1p1 /mnt/upload_disk2 xfs defaults,nofail 0 0
/dev/nvme1n1p1 /mnt/backup_disk1 xfs defaults,nofail 0 0
/dev/nvme2n1p1 /mnt/backup_disk2 xfs defaults,nofail 0 0
Setup NFS
Update apt repo
sudo apt update
Install NFS server
sudo apt install nfs-kernel-server
Add configuration for NFS
sudo vim /etc/exports
Add the following content
/mnt/upload_disk1 *(rw,async,no_subtree_check,no_root_squash,no_all_squash)/mnt/backup_disk1 *(rw,async,no_subtree_check,no_root_squash,no_all_squash)
Change permission
sudo chmod 777 /mnt/*
Restart NFS server
sudo systemctl restart nfs-kernel-server.service
Setup backup using Lsyncd
Install Lsyncd
sudo apt install lsyncd
Make directory for configuration
sudo mkdir /etc/lsyncd
Create configuration file
sudo vim /etc/lsyncd/lsyncd.conf.lua
Add the following content
—— User configuration file for lsyncd.
—- Simple example for default rsync, but executing moves through on the target.
—- For more examples, see /usr/share/doc/lsyncd*/examples/–settings
{
logfile = “/var/log/lsyncd/lsyncd.log”,
statusFile = “/var/log/lsyncd/lsyncd.status”,statusInterval = 2
}
— Slave server configuration
sync {
default.rsync,
delete= false,
source= “/mnt/upload_disk1”,
target= “/mnt/upload_disk2”,
rsync={
archive = true,
verbose = true
}
}
sync {
default.rsync,
delete= false,
source= “/mnt/backup_disk1”,
target= “/mnt/backup_disk2”,
rsync={
archive = true,
verbose = true
}
}
Restart service
sudo systemctl restart lsyncd
Setup firewall rules
sudo ufw allow from 172.32.0.0/24 to any port nfs