Backup Critical Data


Attach the target drive to the computer then issue the fdisk command as follows.
[codesyntax lang=”bash”]

sudo fdisk -l 
[sudo] password for archman: 
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: WDC  WDS100T2B0A
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9a92db95

Device     Boot  Start        End    Sectors   Size Id Type
/dev/sda1  *      6144     415743     409600   200M  c W95 FAT32 (LBA)
/dev/sda2       421888 1953523711 1953101824 931.3G 83 Linux


Disk /dev/zram0: 3.82 GiB, 4099932160 bytes, 1000960 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdb: 111.79 GiB, 120034123776 bytes, 234441648 sectors
Disk model: 2115            
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x7689cbd0

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdb1        2048 234440703 234438656 111.8G 83 Linux

[/codesyntax]
Mount the device by using the following command.
[codesyntax lang=”bash”]

sudo mount /dev/sdb1 /mnt/sdb1

[/codesyntax]
For sanity’s sake we will list the contents of the mounted device.
[codesyntax lang=”bash”]

ls -alh /mnt/sdb1
total 342M
drwxr-xr-x  8 root root 4.0K Apr  9 15:23 .
drwxr-xr-x  1 root root    8 Apr  9 20:35 ..
-rw-r--r--  1 root root 216K Dec 23  2020 bcswebtools.sql
-rw-r--r--  1 root root 6.4K Dec 23  2020 cbill.sql
-rw-r--r--  1 root root 332M Dec 17  2020 code_snippets-master.zip
drwxr-xr-x 38 root root  16K Apr  9 15:38 Documents
-rw-r--r--  1 root root   28 Dec 27  2020 email.txt
lrwxrwxrwx  1 root root    7 Jan  7  2021 lib -> usr/lib
-rw-r--r--  1 root root   26 Jan  7  2021 libname.txt
drwxr-xr-x  2 root root 4.0K Jan  7  2021 libs
-rwxr-xr-x  1 root root  11M Jan  7  2021 libwx_gtk3u_core-3.1.so.4
drwxr-xr-x  3 root root 4.0K Jan  7  2021 libz
drwx------  2 root root  16K Dec  7  2020 lost+found
drwxr-xr-x  2 root root 4.0K Dec 17  2020 openvpn
-rw-r--r--  1 root root  330 Feb  5  2021 url.txt
drwxr-xr-x 42 root root 4.0K Apr  9 15:21 workspace

[/codesyntax]
We shall remove the workspace directory on the mounted drive by issuing the following command.
[codesyntax lang=”bash”]

sudo rm -r /mnt/sdb1/workspace
[sudo] password for archman:

[/codesyntax]
Copy the source directory recursively so no data is omitted.
[codesyntax lang=”bash”]./bk01.sh
Fri Apr 14 06:30:02 AM EDT 2023
Fri Apr 14 06:37:45 AM EDT 2023

sudo cp -r ~/workspace /mnt/sdb1/workspace

[/codesyntax]
Our backup script is listed below.
[codesyntax lang=”bash”]

date
echo sudo rm -r /mnt/sdb1/$1
sudo rm -r /mnt/sdb1/$1
date
date
echo sudo cp -r ~/$1 /mnt/sdb1/$1
sudo cp -r ~/$1 /mnt/sdb1/$1
date

[/codesyntax]
The main script is listed below.
[codesyntax lang=”bash”]

./bk01.sh workspace
./bk01.sh Documents

[/codesyntax]
The execution of out backup script is as follows.
[codesyntax lang=”bash”]

/bk02.sh 
Fri Apr 14 08:43:24 AM EDT 2023
sudo rm -r /mnt/sdb1/workspace
[sudo] password for archman: 
Fri Apr 14 08:43:33 AM EDT 2023
Fri Apr 14 08:43:33 AM EDT 2023
sudo cp -r /home/archman/workspace /mnt/sdb1/workspace
Fri Apr 14 08:51:09 AM EDT 2023
Fri Apr 14 08:51:09 AM EDT 2023
sudo rm -r /mnt/sdb1/Documents
[sudo] password for archman: 
Fri Apr 14 08:51:25 AM EDT 2023
Fri Apr 14 08:51:25 AM EDT 2023
sudo cp -r /home/archman/Documents /mnt/sdb1/Documents
Fri Apr 14 09:23:55 AM EDT 2023
[archman@archlinux ~]$ ls -alh /mnt/sdb1
total 342M
drwxr-xr-x 8 root root 4.0K Apr 14 08:51 .
drwxr-xr-x 1 root root 8 Apr 9 20:35 ..
-rw-r--r-- 1 root root 216K Dec 23 2020 bcswebtools.sql
-rw-r--r-- 1 root root 6.4K Dec 23 2020 cbill.sql
-rw-r--r-- 1 root root 332M Dec 17 2020 code_snippets-master.zip
drwxr-xr-x 38 root root 16K Apr 14 09:23 Documents
-rw-r--r-- 1 root root 28 Dec 27 2020 email.txt
lrwxrwxrwx 1 root root 7 Jan 7 2021 lib -> usr/lib
-rw-r--r-- 1 root root 26 Jan 7 2021 libname.txt
drwxr-xr-x 2 root root 4.0K Jan 7 2021 libs
-rwxr-xr-x 1 root root 11M Jan 7 2021 libwx_gtk3u_core-3.1.so.4
drwxr-xr-x 3 root root 4.0K Jan 7 2021 libz
drwx------ 2 root root 16K Dec 7 2020 lost+found
drwxr-xr-x 2 root root 4.0K Dec 17 2020 openvpn
-rw-r--r-- 1 root root 330 Feb 5 2021 url.txt
drwxr-xr-x 42 root root 4.0K Apr 14 08:51 workspace

[/codesyntax]

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *