Backup methods (III): dd / tar
Making backups regularly is one of the most relevant tasks for a Linux user. In this third chapter of ‘Backup methods’ I will show you two other methods for backing up using basic commands like
Table of Contents
You can copy entire disks to a file using
dd. Just take note of the name of the disk you want to back up (e.g.:
dd if=/dev/sdb of=disk-backup.dd bs=1024
- Backup file must be in another disk.
- You can name your backup file whatever you want, and use the suffix you want (
bs=<bytes>: read and write up to
<bytes>bytes at a time. You can tweak this setting to improve backup speed (default value is 512).
- Backup file size will be the same as disk size.
To restore a backup, just do the opposite:
dd if=disk-backup.dd of=/dev/sdb bs=1024
- This will overwrite ‘sdb’ data.
- I think it’s better to use the same
bsnumber you used when backing up.
You can backup partitions the same way.
You can archive folders or an entire filesystem using
tar cf backup.tar myfolder/
cstands for “create”,
fstands for “archive file”.
- You can optionally use a dash (
-) before the parameters like most commands.
You can compress the file (using gzip) with the
tar czf backup.tar.gz myfolder/
When you want to restore a backup:
tar xpf backup.tar
pmeans “extract file permissions”.
- It will extract the contents in the working directory (the directory in which you are running the commands). If you just archived one folder (like the previous command), it will create that folder. If you archived several folders or files (
tar cf backup.tar file1 file2 file3) you may want
tarto create a folder for the archived contents. In this case, add this parameter:
- Extract gzip compressed tar files with the
You can create multi-volume archives (split files) with
tar -cML 100M -f multivolume.tar.part01 myfolder/
- It will show you a prompt every time
tarfinishes creating a part. You will need to type
nand the file name of that part.
Prepare volume #2 for ‘multivolume.tar.part01’ and hit return: n multivolume.tar.part02 Prepare volume #3 for ‘multivolume.tar.part02’ and hit return: n multivolume.tar.part03 Prepare volume #4 for ‘multivolume.tar.part03’ and hit return: n multivolume.tar.part04
To extract a multi-volume archive, just add the
M parameter and type
n and the file names when the program asks you for it.
$ tar -xMf multivolume.tar.part01 --one-top-level=extract Prepare volume #2 for ‘multivolume.tar.part01’ and hit return: n multivolume.tar.part02 Prepare volume #3 for ‘multivolume.tar.part02’ and hit return: n multivolume.tar.part03 Prepare volume #4 for ‘multivolume.tar.part03’ and hit return: n multivolume.tar.part04
- Remember that
--one-top-level=<folder>creates a folder for the extracted contents.
In Debian/Ubuntu systems, you can use
dpkg-reconfigureto reconfigure an installed package using intuitive dialogs. I will show you how to use this command to change some system settings.
If you have a scanned PDF and you want to be able to search and copy text from it, in this tutorial I will show you how to do it.
If you want to do X11 forwarding from your container to your host, you can type these simple commands.
If you don’t have a Graphical User Interface (GUI) on your Linux device, or you need a simple text-based web browser, I will show you a couple of great programs.
A comprehensive list of Linux-related websites sorted by categories.