DEV Community

Mihika
Mihika

Posted on

Update | Backup | Recover | Kali Linux | Simple Guide

Maintaining up-to-date systems alongside regular backups is crucial for ensuring both the security and recover-ability of your Kali Linux environment.
Without wasting time, read the below article.

To update the Linux OS:

open the terminal, and type the below commands one by one.

> sudo apt update
> sudo apt upgrade
> sudo apt autoremove
> cat /etc/os-release

sudo apt update           #update the package list
sudo apt upgrade          #update the packages to the latest version
sudo apt full-upgrade     #complete system update
sudo apt autoremove       #clean up unnecessary packages 
cat /etc/os-release       #check version of OS
Enter fullscreen mode Exit fullscreen mode

To update the Browser:

> sudo apt update
> sudo apt upgrade firefex-esr
verify the update : Open firefox > help > about firefox > check version


In IT, a backup refers to storing a copy of valuable assets—such as your critical data and system configurations—in a secure location. This allows you to restore the original data or system if they become corrupted, damaged, or otherwise inaccessible. Recovery is the process of retrieving data from a backup after such an event.

If files are accidentally deleted and no backup is available, the process of attempting to recover the lost data is known as data recovery. This involves using specialized software or services to recover deleted files from storage media like hard drives, SSDs, USB drives, or memory cards. When files are deleted, the data isn’t immediately erased; instead, the space it occupied is marked as available for new data. Data recovery tools can sometimes retrieve these files before they are overwritten, although success is not guaranteed, and the chances decrease as new data is written to the storage medium.

Understanding and implementing backup and recovery processes is fundamental for anyone working in IT.

Types of Backup:

1. Full Backup : A comprehensive backup that includes your entire system, all important data, production data, databases, and everything else. It creates a complete snapshot of your system at a specific point in time.
2. Incremental Backup : This type of backup only saves the data that has changed since the last backup, whether it was a full backup or another incremental backup. It’s faster and requires less storage space.
3. Differential Backup : A backup that saves all the changes made since the last full backup. Each differential backup grows in size over time as it accumulates all changes since the last full backup, making recovery faster than with incremental backups.

Summary :Full = you back up all your data.
Incremental = Only new changes since the last backup.
Differential = All changes since the last full backup.

Backup Tools in Kali Linux:

command-line tools like rsync, tar, and dd.
Third-party tools like Deja Dup, Timeshift, and Clonezilla.

Creating a Backup Plan:

  1. Deciding what to back up (critical files, entire system, configurations).
  2. Choosing the right backup schedule and frequency.
  3. Where to store backups (local, external, cloud).

Step-by-Step Backup Process:

You take Backup of your complete Filesystem and all data and keep it at safe place like external drive. when your system infected when a malware or got corrupted somehow, disconnect yourself from internet, use antivirus software to scan and remove the malware, reset your system and restore the Backup.

Before taking backup, Run the below command in terminal to estimate the size of your backup by checking the disk usage of the directories. And excluding the directories that need not to be back up.

> sudo du -shc / --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run --exclude=/tmp --exclude=/mnt --exclude=/media --exclude=/lost+found

Enter fullscreen mode Exit fullscreen mode

Step 1 : Using rsync for complete backup of the Filesystem.

rsync is the most simplest and efficient way to take backup.
following the command to take backup.

> sudo apt-get install rsync
> sudo rsync -aAXv / /path/to/backup/folder --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}
Enter fullscreen mode Exit fullscreen mode

The first command is to install the rsync tool and second command to take backup. Write the commands as mentioned, replace '/path/to/backup/folder' with the actual location where you want to save the backup.
Here’s a breakdown of the options:
-a: Archive mode; preserves permissions, timestamps, and symbolic links.
-A: Preserves ACLs (Access Control Lists).
-X: Preserves extended attributes.
-v: Verbose; shows progress.
--exclude=: Uses a file to specify which files and directories to exclude.
Verify the Backup: After the rsync command completes, check the backup directory to ensure all files have been copied correctly.

Step 2 : Using tar for compressing and archiving.

Follow the below command to compress the backup folder.

> tar -czvf backup_folder.tar.gz -C /path/to/backup backup_folder

Enter fullscreen mode Exit fullscreen mode

Replace '/path/to/backup backup_folder' with the path where you stored the backup. Example, If the location of backup is '/home/user1/backup_folder'. then the command will be like this:

> tar -czvf backup_folder.tar.gz -C /home/user1 backup_folder

Here's what each option does:
-c: Creates a new archive.
-z: Compresses the archive with gzip.
-v: Shows the progress in the terminal.
-f: Specifies the filename of the archive.
-C /home/user1: Changes to the directory where backup_folder is located before creating the archive.

This will create a compressed backup_folder.tar.gz in your /home/user1 directory. Store the backup in an external drive.

Now, how to restore that backup:
If the Backup is in the external drive, connect the drive to your system or if it is somewhere in cloud storage platform, download it and run this command.
> sudo rsync -aAXv /path/to/backup/folder/ /

Replace '/path/to/backup/folder/' with the location where the backup is located.


How to use rsync for backing up a folder:

To take backup of Important data:
> sudo rsync -aAXv /home/ /path/to/backup/location/home_backup/

Here, I am Taking backup of complete /home directory. Replace '/path/to/backup/location/home_backup/' with the location where you want to store it for now. After that store it in external drive or use any cloud storage platform.

To Retore the folder, in case it got deleted or something happened use the below command:
> sudo rsync -aAXv /path/to/backup/location/home_backup/ /home/


Automating Backups:

To schedule backups using rsync, you can use cron to automate the process. Open the terminal, follow the command:

Open the Crontab Editor:

crontab -e
Enter fullscreen mode Exit fullscreen mode

Add a Cron Job: Add a line to schedule your backup:

0 2 * * * /usr/bin/rsync -aAXv / /path/to/external/drive --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}
Enter fullscreen mode Exit fullscreen mode

This line will run a backup every day at 2 AM.
To Exit the crontab editor:
Save: Press Ctrl + O (write out).
Confirm: Press Enter to confirm the filename.
Quit: Press Ctrl + X to exit.

  • 0 2 * * *: Schedule to run at 2:00 AM every day.

  • /usr/bin/rsync: Path to the rsync command.

  • -aAXv: Options to preserve file attributes, permissions, and show progress.

  • /: Source directory (root filesystem).

  • /path/to/external/drive: Destination for the backup, path where you want the backup to be stored.

  • --exclude={...}: Exclude directories that don’t need to be backed up.
    Save and Exit: Save the crontab file and exit the editor. The cron job will now automatically run according to the schedule.

Keep this chart for setting time and date, according to you:

+-------+-------+-------+-------+-------+
| Min   | Hour  | Day   | Month | Week  |
+-------+-------+-------+-------+-------+
| 0-59  | 0-23  | 1-31  | 1-12  | 0-7   |
+-------+-------+-------+-------+-------+
Enter fullscreen mode Exit fullscreen mode

In above cron job 0 2 * * * means no minutes are set, hour is 2 which is in AM , * (asterisk) mean every time, so every day, every month, and every week.

Top comments (0)