sBlock - Backup on Debian, Ubuntu and Related OS
Publisher: Psychz Networks, January 04,2025This guide will walk you through setting up a backup system on your Debian, Ubuntu, and related Linux distributions (Pop!_OS, Linux Mint, Zorin OS, and Elementary OS) using our block storage, which communicates via the iSCSI protocol. The steps are similar across these distributions.
Prerequisites
- A server or workstation running Debian, Ubuntu, or a related OS with root or sudo privileges.
- Access to your iSCSI block storage target.
- The open-iscsi package installed.
Step 1: Install the iSCSI Initiator
First, install the required package:
sudo apt update && sudo apt install open-iscsi -y
Enable and start the iSCSI service:
sudo systemctl enable --now open-iscsi
Step 2: Discover Available iSCSI Targets
Use the following command to discover the iSCSI storage target. Replace [Your_iSCSI_Target_IP] with your actual iSCSI target address.
sudo iscsiadm -m discovery -t sendtargets -p [Your_iSCSI_Target_IP]
Step 3: Log in to the iSCSI Target
Edit the iscsid.conf file and add your login details
vi /etc/iscsi/iscsid.conf
Now login to access the sBlock
sudo iscsiadm -m node -T [Target_Name] -p [Your_iSCSI_Target_IP] --login
To make the login persistent across reboots:
sudo iscsiadm -m node -T [Target_Name] -p [Your_iSCSI_Target_IP] --op update -n node.startup -v automatic
Step 4: Verify the Attached Disk
Check if the new block storage is available:
lsblk
Sample output
loop0 7:0 0 55M 1 loop /snap/core18/1880
loop2 7:2 0 71.3M 1 loop /snap/lxd/16099
loop3 7:3 0 44.3M 1 loop /snap/snapd/23258
loop4 7:4 0 55.4M 1 loop /snap/core18/2846
loop5 7:5 0 63.7M 1 loop /snap/core20/2434
loop6 7:6 0 91.9M 1 loop /snap/lxd/29619
sda 8:0 0 10G 0 disk
└─mpatha 253:0 0 10G 0 mpath
sr0 11:0 1 1024M 0 rom
vda 252:0 0 60G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 59G 0 part /
└─vda3 252:3 0 1G 0 part [SWAP]
Step 5: Format and Mount the Block Storage
Format the disk (replace /dev/sdX with your actual device name):
sudo mkfs.ext4 /dev/sdX
Create a mount point and mount the disk:
sudo mkdir /mnt/blockstorage
sudo mount /dev/sdX /mnt/blockstorage
To make the mount persistent, add an entry to /etc/fstab:
echo "/dev/sdX /mnt/blockstorage ext4 defaults 0 0" | sudo tee -a /etc/fstab
Step 6: Set Up Automated Backups
Option 1: Using rsync for File Backups
To back up files to the mounted block storage:
rsync -av --progress /path/to/source /mnt/blockstorage/backup/
To automate backups, add a cron job:
crontab -e
Add the following line to schedule a daily backup at 2 AM:
0 2 * * * rsync -av --delete /path/to/source /mnt/blockstorage/backup/
Option 2: Using tar for Archival Backups
Create a compressed backup archive:
tar -czvf /mnt/blockstorage/backup_$(date +%F).tar.gz /path/to/source
Option 3: Using BorgBackup for Efficient Backups
Install BorgBackup:
sudo apt install borgbackup -y
Initialize a backup repository:
borg init --encryption=repokey /mnt/blockstorage/borg-repo
Backup data:
borg create --progress --stats /mnt/blockstorage/borg-repo::backup-$(date +%F) /path/to/source
Step 7: Verify and Restore Backups
For rsync Backups
To restore files:
rsync -av /mnt/blockstorage/backup/ /restore/path/
For tar Archives
Extract backup files:
tar -xzvf /mnt/blockstorage/backup_YYYY-MM-DD.tar.gz -C /restore/path/
For BorgBackup Archives
Restore the latest backup:
borg extract /mnt/blockstorage/borg-repo::backup-$(date +%F) --target /restore/path/
Conclusion
You have successfully set up block storage on Debian, Ubuntu, and related distributions, configuring an automated backup solution using iSCSI.