How to create File System Backup using Bash Script on Debian 12
- 01:04 cat /etc/os-release
- 01:13 mkdir -p /var/Backup/CompressedFilesystem
- 01:45 mkdir -p /Backup/Filesystem1/{filesystem1.1,filesystem1.2,filesystem1.3}
- 02:22 mkdir -p /Backup/Filesystem2/{filesystem2.1,filesystem2.2,filesystem2.3}
- 03:12 ls -la /Backup/Filesystem2
- 03:26 vim filesystembackup
- 04:40 chmod +x filesystembackup
- 04:51 ./filesystembackup
To Create File System Backup Using Bash Script On Debian 12
Introduction:
A file system backup is a critical procedure for duplicating and safeguarding vital data from a computer or device to an alternative location. This practice guarantees that in the event the primary data is compromised, destroyed, or corrupted, it can be recovered from the backup. Backups are commonly saved on distinct devices such as external hard drives, cloud storage platforms, or network storage devices. They act as a protective measure against data loss stemming from hardware malfunctions, inadvertent deletions, cyber threats, or unforeseen events. Consistently conducting backups is imperative for safeguarding valuable data and maintaining seamless business operations.
Procedure:
Step 1: Check the OS version by using the following command.
root@linuxhelp:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL=https://bugs.debian.org/
Step 2: Create Destination Directory for the Backup File by using the following command.
root@linuxhelp:~# mkdir -p /var/Backup/CompressedFilesystem
Step 3: Create Sample File System Directory by using the following command.
root@linuxhelp:~# mkdir -p /Backup/Filesystem1/{filesystem1.1,filesystem1.2,filesystem1.3}
Step 4: Again create another File System Directory by using the following command.
root@linuxhelp:~# mkdir -p /Backup/Filesystem2/{filesystem2.1,filesystem2.2,filesystem2.3}
Step 5: Check the Created Directory by using the following command.'
root@linuxhelp:~# ls -la /Backup/Filesystem2
total 20
drwxr-xr-x 5 root root 4096 Jul 7 11:16 .
drwxr-xr-x 5 root root 4096 Jul 7 11:16 ..
drwxr-xr-x 2 root root 4096 Jul 7 11:16 filesystem2.1
drwxr-xr-x 2 root root 4096 Jul 7 11:16 filesystem2.2
drwxr-xr-x 2 root root 4096 Jul 7 11:16 filesystem2.3
Step 6: Create script to take backup automatically by using the following command.
root@linuxhelp:~# vim filesystembackup
#!/bin/bash
# Destination folder path specify using variable
Backup_Destination="/var/Backup/CompressedFilesystem"
# Specify File System with the path using variable
File_System="/Backup/Filesystem1 /Backup/Filesystem2"
# Get date for name of compressed file
Date=$(date +%F)
# Get Hostname for name of compressed file
Hostname=$(hostname -s)
# Specify the structure of compressed file with path using variable
Compressed_File=$Backup_Destination/$Hostname-$Date.tar.gz
# Display Information of Backup Process
echo "Backup Started From $File_System To $Compressed_File"
echo
echo "Day $(date)"
echo
# Take Backup using tar command
tar czf $Compressed_File $File_System
# Display the Information about the Backup Completion
echo "Backup Completed"
echo
echo "$(date)"
echo
# Display the Backup file with the size in a user readable format
echo
ls -lh $Backup_Destination
echo
Step 7: Make the executable permission to the script file by using following ocmmand.
root@linuxhelp:~# chmod +x filesystembackup
Step 8: Run the script file by using following command.
root@linuxhelp:~# ./filesystembackup
Backup Started From /Backup/Filesystem1 /Backup/Filesystem2 To /var/Backup/CompressedFilesystem/linuxhelp-2024-07-07.tar.gz
Day Sunday 07 July 2024 11:33:33 AM IST
tar: Removing leading `/' from member names
Backup Completed
Sunday 07 July 2024 11:33:33 AM IST
total 4.0K
-rw-r--r-- 1 root root 200 Jul 7 11:33 linuxhelp-2024-07-07.tar.gz
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to create File System Backup using Bash script on Debian 12. Your feedback is much welcome.
Comments ( 0 )
No comments available