LinuxShellSite
CommandDescriptionPlatform
tarArchives files and directories into a single file and can also compress them.All Linux distributions
rsyncSynchronizes files and directories locally or over the network, efficiently through delta transfer.All Linux distributions
ddCopies and converts block-level files; commonly used for creating disk images.All Linux distributions
CPIOCopies files to or from archives; Often combined with Find or LS.All Linux distributions
gzip / gunzipCompresses and decompresses files using the gzip algorithm.All Linux distributions
bzip2 / bunzip2Compresses and decompresses files using the bzip2 algorithm (better compression than gzip).All Linux distributions
zip / unzipCompresses and decompresses files in ZIP format; compatible with Windows ZIP files.All Linux distributions
SCPSecure file transfer command over SSH; can be used for copying backups over the network.All Linux distributions
SFTPSecure FTP over SSH; can be used for interactive file transfers.All Linux distributions
mysqldumpCreates a backup of a MySQL/MariaDB database to a text file with SQL commands to restore.Requires MySQL/MariaDB
pg_dumpCreates a backup of a PostgreSQL database.Requires PostgreSQL
lvmLogical Volume Manager commands such as lvcreate, lvsnapshot for snapshots of logical volumes.All Linux distributions with LVM support
dumpCreates block-level backups of file systems (mainly for ext2/3/4).All Linux distributions
restoreRestores files from backups created with dump.All Linux distributions
cpCopies files and directories; can be used for simple backups.All Linux distributions
cp -aCopies files and directories and preserves all attributes; useful for backups.All Linux distributions
cron / crontabScheduling of recurring tasks; can be used to automate backups.All Linux distributions
rsnapshotScript-based tool for backups with rsync and hardlinks for incremental backups.Installation required
rdiff backupPerforms incremental backups; combines the advantages of rsync and revision control.Installation required
borgDeduplicating backup tool with encryption support.Installation required
DuplicityEncrypted incremental backups with support for various storage destinations (local, FTP, SSH, cloud services).Installation required
TimeshiftSystem backup and restore tool similar to “System Restore” on Windows.Mainly Ubuntu/Debian-based systems
fsarchiverFlexible tool for backing up file systems to a compressed archive file.Installation required
partcloneTool for cloning partitions and file systems; supports many file system types.Installation required
testdiskData recovery tool to recover lost partitions and files.Installation required

Notes:

  • Platform: Most commands are available on all major Linux distributions. Some specialized tools may need to be installed.
  • Installing packages:
    • Ubuntu/Debian: sudo apt-get install packagename
    • RHEL/CentOS/Fedora: sudo yum install packagename or sudo dnf install packagename

Examples

  1. Creating a compressed archive using tar:
    tar -czvf backup.tar.gz /path/to/directory
    # -c creates a new archive
    # -z compressed with gzip
    # -v shows progress
    # -f specifies the filename of the archive
  1. Restoring an archive using tar:
    tar -xzvf backup.tar.gz -C /target/path
    # -x extracts the archive
    # -C specifies the target directory
  1. Syncing files with rsync:
    rsync -avz /source/ user@remote_host:/target/
    # -a Archive mode (includes recursive, permissions, times)
    # -v verbose, shows detailed information
    # -z compresses during transmission
  1. Creating a disk image with dd:
    dd if=/dev/sdX of=/path/to/backup.img bs=4M status=progress
    # if=input file (source device)
    # of=output file (target file)
    # bs=block size
    # status=progress shows progress
  1. Automated backup with cron:
    crontab -e
    # Add the following line to create a backup at 2 a.m. every day
    0 2 * * * /usr/bin/rsync -a /source/ /target/
  1. Database backup with mysqldump:
    mysqldump -u username -p databasename > datenbank_backup.sql
  1. Database backup with pg_dump:
    pg_dump -U username database name > datenbank_backup.sql
  1. Using lvm for snapshots:
    lvcreate –size 1G –snapshot –name snapshot_name /dev/vgname/lvname
  1. Incremental backups with rsnapshot:
    • Installation:
      sudo apt-get install rsnapshot # Ubuntu/Debian
      sudo yum install rsnapshot # RHEL/CentOS
  • Configuration: Edit /etc/rsnapshot.conf according to your needs.
  • To perform a backup:
    sudo rsnapshot daily
  1. Backups with borg:
    • Installation:
      sudo apt-get install borgbackup # Ubuntu/Debian
      sudo yum install borgbackup # RHEL/CentOS
  • To create a repository:
    borg init –encryption=repokey /path/to/repository
  • To create a backup:
    borg create /path/to/repository::backup-{now:%Y-%m-%d} /data/source

Additional recommendations:

  • Review backups: Make sure backups are tested regularly to ensure recoverability.
  • Security: Protect your backups with encryption, especially if they’re stored off-site or in the cloud.
  • Backup strategy: Implement the 3-2-1 backup rule:
    • 3 Copies of your data
    • 2 different storage media
    • 1 copy off-site (off-site)
  • Documentation: Maintain detailed documentation of your backup and restore processes.

Important directories for backups on Linux:

  • /etc: Configuration Files
  • /home: User files and settings
  • /var/www: web server files (if a web server is used)
  • Database directories (depending on the database)
  • Individual application data