• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, June 6, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Use GNU Tar to Backup Linux

How VPS by How VPS
January 1, 2020
in Linux
0
0
SHARES
28
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Basic Syntax
  3. Enhancements
    1. Exclude files that you won’t want (or need) to backup.
    2. Add current date to the name of backup
    3. Use a better compression program other than GZip
    4. Putting everything in a shell script
  4. Want to contribute?


Introduction

Now that you have a perfectly configured Linux server on Vultr, you need to choose a backup solution for it. GNU tar is a very good choice – it’s reliable and makes it easy to backup and restore a server.

Basic Syntax

Tar uses the following syntax.

sudo /usr/bin/tar -czpvf /home/john/backup/linux_backup.tar.gz /
  • -c: Archive.
  • -z: Use GZip format to backup. GZip is fast but it generates a larger file size than other compression tools.
  • -p: Preserve permission so that when you restore the backup you will not encounter a permission problem.
  • -v: Show details during backup. Omit -v if you don’t want to see verbose output.
  • -f: Specify where to store the tar files. Here we save the backup file to backup directory under user John’s home directory and name it linux_backup.tar.gz.
  • /: The Linux root file system. This means to backup the whole disk including all mounted drives, so be careful, make sure to exclude folders or files that you don’t want to backup with excluded.txt (explained below).

Enhancements

Exclude files that you won’t want (or need) to backup.

sudo /usr/bin/tar --exclude-from=/home/john/exclude.txt -czpvf /home/john/backup/linux_backup.tar.gz /

Use --exclude-from=/home/john/exclude.txt to specify excludes in a file. An exclude.txt sample is pasted below.

/home/john/backup/*
/tmp/*
/proc/*
/dev/*
/sys/*
/run/*
/var/tmp/*
/var/run/*
/var/lock/*
/usr/portage/*
/usr/src/*

In this example, I exclude /home/john/backup/*, otherwise the first backup will be included in the second backup, and so forth.

On every Linux system, the /tmp/*, /proc/*, /dev/*, /sys/*, and /run/* are dynamically created, so you don’t need to include them in the backup, but you need to keep the directory structure. Therefore, you need to use /proc/* in the excluded.txt, as opposed to /proc.

You can add other files and folders that you don’t want to backup. In the example above, I have included /usr/portage/* and /usr/src/*. These are Gentoo Linux specific. The first one contains the Gentoo package ebuilds and sources. The second one contains Gentoo Linux kernel sources. They are big, and can both be downloaded again after a system restore. Feel free to edit the excluded.txt to suit your needs.

Add current date to the name of backup

 sudo /usr/bin/tar --exclude-from=/home/john/exclude.txt -czpvf /home/john/backup/linux_backup-$(date +%F-%H-%M).tar.gz /

With $(date +%F-%H-%M), the current date, hours, and minutes will be added to the backup file name. For example, linux_backup-2015-07-02-15-22.tar.gz.

Use a better compression program other than GZip

sudo /usr/bin/tar --exclude-from=/home/john/exclude.txt -cJpvf /home/john/backup/linux_backup-$(date +%F-%H-%M).tar.xz /

The -J switch can replace -z to use Xz for compression. It also changes the extension to tar.xz. Xz is slower than GZip, but it has a much better compression ratio, which results in a smaller backup file.

Putting everything in a shell script

Create a script.

vim /home/john/bin/linux_backup.sh

Include the following code in the script.

#!bin/sh
_tarfile=/home/john/backup/linux_backup-$(date +%F-%H-%M).tar.xz
sudo /usr/bin/tar --exclude-from=/home/john/exclude.txt -cJpvf $ /

Grant the script execute permissions.

 sudo chmod +x  /home/john/bin/linux_backup.sh

Perform a backup.

 /home/john/bin/linux_backup.sh

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Installing Let’s Encrypt on DirectAdmin

Next Post

How to Install LiteCart Shopping Cart Platform on Ubuntu 16.04

Next Post

How to Install LiteCart Shopping Cart Platform on Ubuntu 16.04

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In