Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Lot of guides focus on how to backup user data, but I'm interested in backing up the current state of my Debian Buster system. Why? Because I've had a few experiences of breaking something or other on my system with an ill-advised install or update, and as a Linux newbie I don't know how to fix it so would like to have a backup of the system that I can just restore.
Does it make sense to use tar for this? I see discussion about directories (and files) that shouldn't be backed-up and restored, but different things in different discussions so my head is kind of spinning. Can anyone suggest a tar command to backup the system in a way that would allow it to be easily restored?
Tar is a wonderful tool for creating an archive (Tape ARchive: it should be) but it is not directly a backup program. It can be used as one part or piece of a backup system or strategy, but it is certainly not a snapshot tool.
I have written systems for the purpose, but it requires knowing EXACTLY where every critical configuration file in your system lives and what applications read that configuration. And even then doing it manually can miss something.
It is easier to do this with BTFS snapshots, but then your entire system must be BTRFS based.
Timeshift is one tool specifically intended for this purpose. This is the kind of solution I would recommend. Using it you can "roll back" recent changes if things go south on you.
Thanks, I appreciate that advice. I did come across Timeshift and thought it looked intriguing, but I haven't been able to find any guides to using it on a headless server. It's probably possible, right?
Here is a timeshift command line guide: https://dev.to/rahedmir/how-to-use-t...-in-linux-1l9b. Note: A proper backup is stored apart from the storage medium that you back up, otherwise it doesn't protect against media failure.
Yeah, that was the one that I found too. Unfortunately it doesn't say anything about how to configure timeshift from the command line, but maybe I can figure that out from the documentation.
If it's headless, that to me says no desktop environment (GUI). What's the point of using a GUI wrapper for rsync ?.
rsync is your friend - maybe have a look at something like rsnapshot for scheduled backups.
This, or (assuming you have 'unlimited hardware resources and time') just clone the system drive(s) to something equivalent and if it 'goes bad' swap to the other drive. This would require some physical intervention and take a lot of time depending on how much data we're talking about. You should be able to do this with dd or get a standalone 'disk cloner' machine (they cost about $30 and usually double as external hard drive docks). Crude but effective. In a GUI, GNOME Disks can create snapshots as well (and it doesn't just run in GNOME), but if you're headless that may not work.
Tar is a wonderful tool for creating an archive (Tape ARchive: it should be) but it is not directly a backup program. It can be used as one part or piece of a backup system or strategy, but it is certainly not a snapshot tool.
I have written systems for the purpose, but it requires knowing EXACTLY where every critical configuration file in your system lives and what applications read that configuration. And even then doing it manually can miss something.
It is easier to do this with BTFS snapshots, but then your entire system must be BTRFS based.
Timeshift is one tool specifically intended for this purpose. This is the kind of solution I would recommend. Using it you can "roll back" recent changes if things go south on you.
Tar was designed to do backups and works very well at the task. Where some go wrong in using it is they fail to make sure the data being archived is static. If a file changes during the backup then corruption can occur. In other words, a tar of an entire OS has to be done by booting from something like a live usb and then running tar on the OS. By using the proper parameters you can archive everything, only a particular directory tree, or even limit the tar file to data on a single partition. Man tar gives you a lot of info on the options avialable, and it for quite some time now even is able to create a compressed tar file and extract same.
I do not understand your statement that tar is not a good archive tool since it is one of the best and has been around since the early days of computers. If it were not capable of the tasks it would have been retired long ago. Certainly there are a lot of others that do backups differently but the old standbys are still very much alive and functional.
A simple and effective way to use tar for backing up any single directory tree, including /, is "tar cvf /path/to/arcive/file.tgz /path/to/directory". this will create the tar file in the directory where you specify and copy all the data in the absolute path given. The tar file will be gzipped as well. Note that the normal permissions rules apply, and the user has to have read access to the data being tarred up.
Read the man page to see what cvf does and also what other options you may wish to use.
Last edited by computersavvy; 07-24-2021 at 07:19 PM.
Tar was designed to do backups and works very well at the task. Where some go wrong in using it is they fail to make sure the data being archived is static. In other words, a tar of an entire OS has to be done by booting from something like a live usb and then running tar on the OS. By using the proper parameters you can archive everything, only a particular directory tree, or even limit the tar file to data on a single partition. Man tar gives you a lot of info on the options avialable, and it for quite some time now even is able to create a compressed tar file and extract same.
I do not understand your statement that tar is not a good archive tool since it is one of the best and has been around since the early days of computers. If it were not capable of the tasks it would have been replaced long ago. Certainly there are a lot of others that do backups differently but the old standbys are still very much alive and functional.
RE-read my post. I did not say "tar is not an archive tool", I said "...Tar is a wonderful archive tool ...". I said it is "not directly a backup program". and stand by that.
Real backup programs allow for generational backups and restore to point in time. Some provide (critical to this users question) snapshot and rollback. There are other tools that provide snapshot and rollback, but TAR is not one of them. He need something that will quickly take a snapshot, and allow him to roll it back if an install or update goes south on him. TAR is a great tool, but it is not THAT tool.
When written tar was the only and an excellent backup tool. Users needs have changed dramatically since, and as you say there are a lot of newer and better tools for snap shots and incremental backups that are now available.
To the OP
Tar is a wonderful tool for static backups, but is not designed for and does not work well for incremental snapshots/backups. It has no concept of changes, only copies everything there at the moment it is run. As suggested above there are better tools for doing any form of backup that is not a "copy everything" while static.
Tar can do updates of files already in the archive, but is not the best for that.
For a single-tool backup of your entire system, so it will boot the old version perfectly, you might look into clonezilla. IT gets all parts of the storage, including the parts that do not mount and that TAR cannot even see.
Well, I was excited about TimeShift, but the docs say that it works only with GRUB2, and my Orange Pi uses U-Boot. I guess I'll check out rsnapshot, clonezilla, and other tools that backup the entire drive (or partition?) rather than just the system.
I am working now on a Pinebook Pro. If I want a snapshot of the system, I just do a dd of the entire internal storage device to a fast SD card. If I need to go back, I can boot form the SD card and DD the image back onto the internal storage (or just run from the SD card for a few days). I see no reason something like that would not work for your RPi.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.