07 Backup dan Restore


  • .

Backup dan Restore

Backup

Backup is the process of creating copies of data to protect against loss due to hardware failure, human error, or malware attacks.

Backup dengan tar

tar (Tape Archive) is a tool for archiving files and directories.

  1. Creating a Backup:

    tar -cvf backup.tar /path/to/directory

    Explanation :

    • -c: Creates a new archive.
    • -v: Displays the backup process.
    • -f: Specifies the archive file name.
  2. Compressing a Backup:

    tar -czvf backup.tar.gz /path/to/directory

    Explanation :

    • -z: Uses gzip for compression.
  3. Restoring a Backup:

    tar -xvf backup.tar -C /path/to/restore

    Explanation :

    • -x: Extracts files from the archive.

Backup with rsync

rsync is a tool for efficiently synchronizing files and directories.

  1. Local Backup:

    rsync -avh /source/directory /destination/directory

    Explanation :

    • -a: Archive mode (copies permissions, timestamps, etc.).
    • -v: Displays the process.
    • -h: Human-readable file size format.
  2. Remote Backup:

    rsync -avz /source/directory user@remote:/destination/directory

    Explanation :

    • -z: Compresses data during transfer.
  3. Incremental Backup: Uses the --link-dest option to store only changes since the last backup:

    rsync -av --link-dest=/previous/backup /source/directory /new/backup

Backup with dd

dd is a tool for creating byte-by-byte copies of disks or partitions.

  1. Creating a Disk Backup:

    dd if=/dev/sdX of=/path/to/backup.img bs=64K status=progress
    • if: Input file (source disk).
    • of: Output file (backup file).
    • bs: Block size.
    • status=progress: Displays progress.
  2. Restoring a Disk:

    dd if=/path/to/backup.img of=/dev/sdX bs=64K status=progress

Backup and Recovery Using Open-Source Software

Amanda

Amanda (Advanced Maryland Automatic Network Disk Archiver) is an open-source backup tool for networks.

  • Key features:

    • Mendukung berbagai media (disk, tape, cloud).

    • Scheduled backups.

    • Easy recovery.

  1. Installing Amanda:

    • Install Amanda packages:

      sudo zypper install amanda-server amanda-client
  2. Configuring the Amanda server: Edit configuration files in /etc/amanda/.

  3. Start the Amanda service:

    sudo systemctl start amanda
  4. Performing a backup:

    amdump DailySet1
  5. Recovering files:

    Amrecover

Bacula

Bacula is an open-source backup software that supports centralized backups for networks.

  • Key features:

    • Supports multiple operating systems.

    • Automated and scheduled backups.

    • Encryption support.

  • Installing Bacula:

    1. Install Bacula packages:

      sudo zypper install bacula
    2. Configure Bacula directory files in /etc/bacula/.

    3. Start Bacula services:

      sudo systemctl start bacula-dir
      sudo systemctl start bacula-sd
      sudo systemctl start bacula-fd
    4. Backup data: Run Bacula commands according to the configuration.

    5. Recover data: Use the Bacula interface or CLI commands to restore data.

Btrfs Snapshots and System Recovery

Snapshots are copies of a file system at a specific point in time. Btrfs supports snapshots as a built-in feature for quick and efficient backups.

Creating Snapshots with Btrfs

  1. Create a snapshot:

    sudo btrfs subvolume snapshot /source /snapshot

    Explanation :

    • /source: Source subvolume.
    • /snapshot: Snapshot location.
  2. Read-only snapshot:

    sudo btrfs subvolume snapshot -r /source /snapshot

Restoring Snapshots

  1. Delete the corrupted subvolume:

    sudo btrfs subvolume delete /source
  2. Restore from a snapshot:

    sudo btrfs subvolume snapshot /snapshot /source

Backing Up Snapshots to an External Disk

  1. Send a snapshot to another disk:

    sudo btrfs send /snapshot | sudo btrfs receive /mnt/backup
  2. Restore from a backup:

    sudo btrfs receive /mnt/backup