System backup. Creating a bootable flash drive for installing Windows using the Rufus program What does dd image mean?

💖 Do you like it? Share the link with your friends

Using the dd utility, we will create an image of a flash drive with archiving of free space. The backup image will come in handy if the original suddenly stops working. important information. For example, a flash drive with private keys electronic signatures management of the organization. So, we have a 4GB flash drive /dev/sdd, the information on which takes up about 90MB.
du - sh / run / media / aleksey / Transcend

89M /run/media/aleksey/Transcend

All commands are executed on behalf of the user root. Or in the corresponding distributions add before the commands sudo.
fdisk - l /dev/sdd

Disk /dev/sdd: 3.7 GiB, 3904897024 bytes, 7626752 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xc653eaa4 Device Boot Start End Sectors Size Id Type /dev/sdd1 2048 7628543 7626496 3.7G b W95 FAT32

Disk /dev/sdd: 3.7 GiB, 3904897024 bytes, 7626752 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0xc653eaa4

Device Boot Start End Sectors Size Id Type

/dev/sdd1 2048 7628543 7626496 3.7G b W95 FAT32

By creating a simple image with the command
dd if = /dev/sdd of = sdd . iso bs = 4M conv = noerror,
we condemn ourselves to storing a 4GB file. What if the flash drive had a capacity of 64GB? And not alone? A regular archiver will help us solve this problem, let’s take a standard one gzip.
dd if=/dev/sdd bs=4M conv=noerror | gzip - c > sdd . iso. zip
where is the key -c allows you to work with standard output.
After completing the work, let's look at the resulting file. ls - al sdd*

The resulting file is approximately 25MB in size. Real savings on disk space even compared to a 4GB file!
To restore a flash drive from an image, use the reverse order of commands.
gunzip - c sdd . iso. zip | dd of = /dev/sdd conv = noerror bs = 4M

You can also archive images hard drives, where the volumes are an order of magnitude larger.

By the way! To make the process clearer, due to dd not having its own progress bar, I suggest using a small utility progress- Coreutils Progress Viewer. Installing it on Fedora is not difficult.
dnf install progress
For other distributions, the required repository can be found at https://pkgs.org/download/progress.
By installing and running the utility with the command watch progress in the second terminal (in the first we have an archiver and dd running) on ​​behalf of the same user, we will see something like this.

man progress will show you various useful keys of this utility.

Be careful because if you misspell the name of the flash drive in the dd command, you can damage the host hard drive.

We will display the partition designation of all devices

and find a flash drive among them:

Sudo fdisk -u -l /dev/sd?

Also, to define partitions on all devices, you can use the command:

Sudo cat /proc/partitions

dd command syntax

dd if=/AAAA of=/BBBB bs=CCCC count=DDDD conv=noerror
  • if: (input file) indicates the source, i.e. to where we are copying from. Specifies a file, which can be either a regular file or a device file.
  • of: (output file) points to the destination file. The same thing, we can write both to a regular file and directly to the device.
  • bs: The number of bytes that will be written at a time. That is, the size of a piece of data that will be read and written at a time. It is recommended to set bs= to the size of the hard drive cache, i.e. 8M 16M 32M
  • count: how many pieces bs will be copied.
  • conv: allows you to connect filters that apply to the data stream. Filter "no error" just disables stopping the program when it encounters a reading error.

Examples

Complete disk erase

So that nothing can be restored on the media, you can fill it with zeros, this command will always end with the error “the media has run out of space”

Dd if=/dev/zero of=/dev/sdX

Creating a disk image

dd if=/dev/cdrom of=image.iso conv=noerror

you can also log into the system

Mount -o loop /PathToImageFile/image.iso /mnt/FolderMount

If something doesn’t work out, the process is divided into 2 levels:

Losetup -e /dev/loop0 /PathToImageFile/image.iso mount /dev/loop0 /mnt/FolderMount

MBR Operations

MBR is located in the first 512 bytes hard drive, and consists of a partition table, a bootloader and a couple of additional ones. byte. Sometimes you have to back it up, restore it, etc. Backup is done like this:

Dd if=/dev/sda of=mbr.img bs=512 count=1

You can restore it more easily:

Dd if=mbr.img of=/dev/sda

Copying with archiving

(using gzip) data from a flash drive to a hard drive.

Dd if=/dev/sdX conv=sync,noerror bs=8M | gzip -c >/PathToSave/sdX.img.gz

and back

Gunzip -c /PathToFile/sdX.img.gz | dd of=/dev/sdX conv=sync,noerror bs=8M

Copying over the network

dd if=/dev/sdX conv=sync,noerror bs=8M | ssh -c blowfish UserName@HostName "dd of=sdX.img.gz bs=8M"

and back

Dd if=sdX.img.gz | ssh -c blowfish UserName@HostName "dd of=/dev/sdX bs=8М"

Team dd is designed to use the utility of the same name, designed for low-level copying and conversion of data. Its name stands for “data duplicator” or “data duplicator”. This utility is used mainly for writing images of installation disks of Linux distributions to flash drives and creating images of optical media, however, its range of functions is not limited to the listed operations. For example, dd can be used for simple copying files or changing the case of text strings. In general, the utility in question is to some extent unique, because it involves the use own format passing parameters.

The standard command syntax is as follows:

$dd if=<имя исходного файла>of=<имя целевого файла>[options]

It is easy to notice that the recording format is used to pass parameters to the utility <имя параметра>=<значение параметра> . The utility can read source data from standard input and output the resulting data using standard output if parameters are not used if And of, but in the vast majority of cases these parameters are necessary to specify file names with the corresponding data. The utility reads and writes data in blocks, and the block size can be changed using the parameter bs(Blocks of 512 KB are used by default). There are separate parameters for setting the sizes of readable and writable blocks, namely, ibs And obs. The number of blocks read can be limited using the parameter count. The parameter can be used to skip a specified number of blocks in the source file. skip, target file - parameter seek. The parameter can be used to specify read and write flags separated by commas iflag

  • append- activation of the mode of appending data to the target file.
  • direct- data processing mode bypassing the file system cache (increases speed).
  • dsync- data recording mode with synchronization (increases reliability).
  • sync- data and metadata recording mode with synchronization (increases reliability).
  • fullblock- reading only complete blocks.
  • nonblock- activation of non-blocking I/O mode (increases speed).
  • noatime- disabling the mechanism for updating file system element timestamps (increases speed).
  • nofollow- refusal to follow symbolic links.

Finally, the parameter can be used to specify comma-separated conversion flags conv. The most commonly used flags are:

  • lcase- converting string characters in ASCII encoding to lower case.
  • ucase- converting string characters in ASCII encoding to upper case.
  • nocreat- display an error message if the target file is missing.
  • excl- display an error message if the target file exists.
  • notrunc- refusal to trim the target file.
  • swab- changing the locations of every two bytes from the source file.
  • noerror- continuation of work even if errors occur.
  • fdatasync- activation of the mode of writing data to the target file before completing the utility.
  • fsync- activation of the mode of writing data and metadata to the target file before completing the utility.

Examples of using

Backing up disk drive data

Suppose we use HDD, represented by the device file /dev/sda, and we need to create a sector-by-sector backup of all the data located on it, saving it in a file in a partition of a removable disk with USB interface, represented by the device file /dev/sdb1 and mounted in the directory /mnt/sdb1. These backup files are usually called dumps or disk images. Our disk image file will be named backup.img. This is the command with which you can create it:

# dd if=/dev/sda of=/mnt/sdb1/backup.img

In this command, using the parameter if the path to the source file is specified, and using the parameter of- to the target.

Restoring data from a backup

To recover data from the created backup copy you should boot the system from installation disk distribution and execute the reverse command.

# dd if=/mnt/sdb1/backup1.img of=/dev/sda

Warning: executing this command will overwrite the entire contents of the specified hard drive, so you should treat such commands with special attention.

Hard drive cloning

Before cloning a hard drive, you must ensure that you have a hard drive that is the same size as the original one. The same operation can be performed in the case of flash drives with a USB interface of similar sizes. Let's assume that the source flash drive is represented by a device file /dev/sdb, and the target - the device file /dev/sdc. In this case, you can clone the source drive using the following command:

# dd if=/dev/sdb of=/dev/sdc

Even if the target drive has a larger capacity, you will only have access to the size of the source flash drive stored at the file system level.

Transferring a disk image file to another computer

To transfer a disk image file over a network to another computer named target the following command can be used:

# dd if=/dev/sdb | ssh root@target "(cat >backup.img)"

Compressing a Disk Image File

To make the backup disk partition take up less space, you can compress it using a compressor such as bzip2 :

# dd if=/dev/sdb | bzip2 backup.img.bz2

Creating an ISO optical disc image

To create an image optical disk A CD, DVD or BD just needs to read its contents block by block and save this content in a file:

# dd if=/dev/sr0 of=image.iso bs=2048

Saving a file from damaged media or creating an image of such media

If your favorite movie or music track is no longer readable due to media corruption, you can try to copy it using the utility dd, ignoring bad blocks:

# dd if=movie.avi of=/home/alex/movie.avi conv=noerror,sync

You can also create an image file of the damaged media and try to extract files from it:

# dd if=/dev/sdb of=/home/alex/movie.iso bs=2048 conv=noerror,sync

Burning an installation disk image to a USB flash drive

For installation Linux distribution from a USB flash drive, you must write an ISO installation disk image to this flash drive. A similar command can be used for this purpose:

# dd if=/home/alex/Fedora-Workstation-Live-x86_64-26_Alpha-1.7.iso of=/dev/sdc

It is important to remember that even if there are partitions on the flash drive, you should not specify the path to the device file of one of the partitions, but the path to the device file of the drive itself, in our case this is /dev/sdc.

Hard drive content analysis

Utility dd is an excellent tool for exploring file systems. To analyze the contents of a hard drive with data output from individual blocks, in our case, a block 1001 on the partition represented by the device file /dev/sdc1, just use the following command:

# dd if=/dev/sdc1 count=1 skip=1000

In order to see the first 40 bytes of your hard drive in hexadecimal notation, use the command:

# dd if=/dev/sda bs=1 count=40 | hexdump -C

In this case, using the parameter bs sets the disk block size.

Testing disk drive performance

For performance testing disk drive, represented, for example, by a device file /dev/sda When reading blocks of different sizes, a similar command can be used:


1000000+0 records in
1000000+0 records out

# dd if=/dev/sda of=/dev/null bs=4096 count=1000000
1000000+0 records in
1000000+0 records out
4096000000 bytes (4.1 GB) copied, 29.8747 s, 137 MB/s

Thanks to the file system caching mechanism, you may encounter a mystical speedup of read operations that should not be surprising:

# dd if=/dev/sda of=/dev/null bs=512 count=1000000
1000000+0 records in
1000000+0 records out
512000000 bytes (512 MB) copied, 4.25186 s, 120 MB/s

# dd if=/dev/sda of=/dev/null bs=512 count=1000000
1000000+0 records in
1000000+0 records out
512000000 bytes (512 MB) copied, 0.417317 s, 1.2 GB/s

To obtain correct test results, it is recommended to bypass the file system caching mechanism altogether by using I/O mode without caching:

# dd if=/dev/sda of=/dev/null bs=512 count=100000 iflag=direct
100000+0 records in
100000+0 records out
51200000 bytes (51 MB) copied, 5.01053 s, 10.2 MB/s

Copying files

Yes, utility dd can even be used for regular file copying. Of course, for this purpose it is better to use a utility specially designed for this purpose, namely, cp. In any case, you can copy the file using a similar command:

$ dd if=/home/alex/test.txt /home/alex/test_copy.txt

As is known, “computer users are divided into those who make backups and those who will do them”. In this article we will look at various ways backup (backup) of the entire system and, accordingly, restoration from a backup copy.

It’s worth noting right away that all operations should not be performed “live”, i.e. not on a running system, but from a liveCD or installed on a neighboring partition/flash drive/usb-hdd of the system. In cases where downtime of a few minutes is critical for the system, it is possible to copy the system from under itself, but in this case some additional conditions must be taken into account, which are not yet considered in this article

Further in the text, for actions performed as a superuser, the sudo command will be used, which is the standard for Ubuntu. On other systems it is possible to gain superuser privileges via su , some liveCD systems run in superuser mode by default

tar

One of the most popular ways to create a simple backup is to archive data using tar. The advantages of this method are the possibility of incremental backup (adding files to existing archive, deleting or changing them), the ability to extract individual files from the archive, as well as the presence of tar in almost any Linux system.

Creating an archive

First, create mount points for the root partition and for the partition on which you are going to create a backup, for example like this

Mount both partitions. For greater reliability, you can mount the root partition in read-only mode to eliminate the possibility of accidental data changes

Sudo mount /dev/sdXY /mnt/root -o ro sudo mount /dev/sdXY /mnt/backup

(Instead of "sdXY" use your values ​​for the partitions you want. You can determine them using sudo fdisk -l or sudo blkid)

If you use separate partitions for /boot, /usr, /home, etc. and want to include their contents in the backup, mount them in the appropriate folders

Sudo mount /dev/sdXY /mnt/root/usr -o ro sudo mount /dev/sdXY /mnt/root/home -o ro

If necessary, create a folder on the backup partition in which you want to place the archive, for example

Sudo mkdir -p /mnt/backup/ubuntu/root

Now you can start creating the archive. To create a gzip-compressed archive, run

Sudo tar -cvzpf -C /mnt/root /mnt/backup/ubuntu-sda1.tar.gz .

(The -p switch enables saving owners and permissions for files)

For bzip2 compression use

Sudo tar -cvjpf /mnt/backup/ubuntu-sda1.tar.bz2 /mnt/root

For lzma compression

Sudo tar --lzma -cvpf /mnt/backup/ubuntu-sda1.tar.lzma /mnt/root

Similarly for lzo compression - switch --lzop instead of --lzma

Different compression algorithms produce different archive sizes and also differ in performance

Once the process is complete, unmount all mounted partitions

Sudo umount /mnt/root(/boot,/var,/home,) /mnt/backup

Restoring from an archive

Create mount points for the root partition and the partition where your archive is stored

Sudo mkdir /mnt/(root,backup)

Mount the partition with the backup archive

Sudo mount /dev/sdXY /mnt/backup -o ro

Format the root partition to the same (or another) file system. If you use separate partitions for /usr, /boot, etc. and archived them, format them too

(if you are restoring the system to new hard disk, partition it using fdisk/gparted and format the partitions)

Some file systems support setting the UUID when formatting. This makes it possible to create a file system with the same UUID as the old one, which will avoid the need to edit fstab.

For ext2/3/4, the UUID is set using the -U switch, and you can simplify the task even further with a command like

Sudo mkfs.ext4 -L "label" -U "$(sudo blkid -o value -s UUID /dev/sda1)" /dev/sda1

If you used archiving when creating the image file, first unpack it using the same archiver, for example

Bzip2 -dv /media/backup/sda5.dd.bz

Now you can mount the image

Sudo mount /media/backup/sda5.dd -o loop /mnt

(With the loop option, the mount program will automatically “pick up” the image file to a free loop device, and then mount the file system)

Now you can work with the contents of the image as with a regular file system, all your changes will be written to the image. When finished, mount the image as a regular file system

Sudo umount /mnt

dd - copy the entire hard drive

In this case, we will use dd again, only this time we will save the entire contents of the hard drive - with the partition table, the partitions themselves and all the data. Advantage this method the fact that you can save all systems installed on this hard drive in one step without having to backup each partition separately. In addition, with such a backup, all data related to the bootloader will be saved - thus, after restoring from the backup, you will not need additional manipulations, you can immediately boot from this hard drive.

Creating an image

In general, the procedure is similar to that described above for backing up individual partitions. In this case, the advice about clearing free space with “zeros” also applies - if you have free time, do this with all partitions.

Before starting the operation, make sure that none of the partitions on this hard drive are mounted. This can be done by running the mount command without parameters.

Select the partition on which you are going to place the clip file. Of course, this must be a partition from another hard drive. Also make sure that there is enough free space on this partition (for example, using the df utility) - the amount of free space should correspond to the volume of the copied hard drive (when compressed, the image will be smaller, but this depends on the type of data stored).

Mount a backup partition

Sudo mount /dev/sdXY /mnt

Now you can start

Sudo dd if=/dev/sdX bs=1M conv=noerror,sync | lzma -cv > /mnt/hdd.dd.lzma

(here “sdX” is a disk, not a partition! for copying without compression, the command is similar to the one above for backing up a partition)

Depending on the size of the hard drive and the performance of the computer, the procedure may take a long time (up to several hours). When finished, mount the backup partition

Sudo umount /mnt

Recovery from image

Attention! This method involves a complete rollback to the state at the time the archive was created with the replacement of all data!

Before starting work, make sure the power supply is reliable. Connect network adapter, if you have a laptop, and if possible use a UPS or stabilizer. High write rates increase the risk of disk damage in the event of a power failure

Make sure that no partition of the disk being restored is in use. Mount a backup partition

Sudo mount /dev/sdXY /mnt

You can start the procedure

Bzip2 -dc /mnt/hdd.dd.bz | sudo dd of=/dev/sdX bs=1M conv=sync,noerror

Or for an uncompressed image

Sudo dd if=/mnt/hdd.dd.bz of=/dev/sdX bs=1M conv=sync,noerror

When finished, mount the backup partition

Sudo umount /mnt

If you want to extract the image to another hard drive, it must be at least as large as the original one. If new disk larger volume, you can expand partitions or create a new partition on free space using parted/fdisk/gparted/etc

Do not use both hard drives (“duplicate” and “original”) at the same time! When both drives are connected, the system will have two partitions for each UUID, which will lead to operational problems or inability to boot

Mounting the image

By analogy with the partition image, you can work with the hard disk image as with a regular hard drive. In this case, the procedure becomes somewhat more complicated, since the image contains several sections.

If the image is compressed, unpack it. Now “pick up” the image to the loop device

Sudo losetup -fv /media/backup/sda.dd

(With the -f switch, the program will automatically find a free loop device, otherwise you must explicitly specify it)

losetup will display the name of the device used - if you are not working with other image files (iso, encrypted containers, etc.), it will most likely be /dev/loop0

Now we have a device that is a hard drive for the system, but we do not have access to its partitions. The kpartx program will help you get to the partitions (you may need to install the package of the same name)

Sudo kpartx -av /dev/loop0

(Key -a - add partitions for a given device; -v - informative output)

The program will display the names of the created devices for the disk partitions: loop0p1 for the first partition, loop0p2 for the second, similar to the partitions of a regular disk. The device files will be located in the /dev/mapper folder

Now you can work with partitions and FS on them. For example, mount the former sda5 and write files to it

Sudo mount /dev/mapper/loop0p5 /mnt

When finished, unmount the partition

Sudo umount /mnt

Remove partition devices using kpartx

Sudo kpartx -dv /dev/loop0

and release the loop device

Sudo losetup -v -d /dev/loop0

All! The changes are recorded, and your image becomes a regular file again

cp

Here we will look at backup using the cp utility, i.e. using simple copying. Actually, it's not the most the best way, and it is more suitable for copying the system to another hard drive / partition / computer, rather than for creating a backup copy.

On the other hand, this method has a number of advantages:

    Universality - you will find cp in any Linux system

    Low resource requirements (due to lack of compression and simplicity of the mechanism)

    Ease of further work with the backup (adding/changing/deleting files, extracting the necessary data, etc.)

Making a copy

Create mount points for the root and backup partitions

Sudo mkdir /mnt/(root,backup)

Mount both partitions

Sudo mount /dev/sdXY -o ro /mnt/root sudo mount /dev/sdXY /mnt/backup

Mount partitions for /usr, /boot, etc., if any

Sudo mount /dev/sdXY -o ro /mnt/root/home

Create a folder for your backup on the backup partition

Sudo mkdir /mnt/backup/ubuntu

We can start

Sudo cp -av /mnt/root/* /mnt/backup/ubuntu

(the -a switch enables copying links “as is”, saving all possible file attributes and recursive mode. -v switch - displaying information about what is happening)

Once the process is complete, unmount all partitions

In the future, you can archive your data in any convenient way.

Restoring from a copy

Attention! This method involves a complete rollback to the state at the time the archive was created, replacing all data!

Create mount points for partitions

Sudo mkdir /mnt/(root,backup)

Mount a backup partition

Sudo mount /dev/sdXY -o ro /mnt/backup

Format the root partition and /usr, /boot, etc. partitions, if any. (For formatting partitions while preserving the UUID, see the section about)

Sudo mkfs.reiserfs -l "root" /dev/sdXY sudo mkfs.ext2 -L "boot" /dev/sdXY sudo mkfs.ext4 -L "home" /dev/sdXY

Mount the newly created file systems

The copying process is similar, only in the opposite direction.

Sudo cp /mnt/backup/ubuntu/* -av /mnt/root

Once the copy is complete, edit fstab to correct the partition UUIDs

Unmount the partitions

Sudo umount /mnt/backup /mnt/root/(usr,home,)

squashfs

sudo mkfs.reiserfs -l "root" /dev/sdXY sudo mkfs.ext2 -L "boot" /dev/sdXY sudo mkfs.ext4 -L "home" /dev/sdXY

Mount the newly created file systems

Sudo mount /dev/sdXY /mnt/root sudo mount /dev/sdXY /mnt/root/usr sudo mount /dev/sdXY /mnt/root/var

We're ready to start! To unpack the image, use the unsquashfs utility

Sudo unsquashfs -d /mnt/root -f /mnt/backup/ubuntu-root.sqfs

(The -d switch specifies the path for unpacking, with the -f switch the program will use existing folders instead of trying to create new ones)

Just like when creating an image, you will see a progress bar and lots of other useful information.

When finished, edit fstab, replacing the partitions' UUIDs with new ones (if you formatted the partitions with the same UUIDs, skip this step)

Sudo nano /mnt/root/etc/fstab

Save the file and unmount all partitions

Sudo umount /mnt/backup /mnt/root(/usr,/var,)

Mounting the image

squashfs is mounted like any other image - via a loop device. Kernel support for squashfs is included in many distributions, including Ubuntu, so you can simply use the mount command with the loop option

Sudo mount /media/backup/ubuntu-root.sqfs -o ro,loop /mnt

(The ro option is not required, since writing nothing there will not work anyway)

Now you can copy any necessary files. Adding something this way will not work; to do this you will need to use mksquashfs again

When finished, mount the image as a regular file system

Sudo umount /mnt

rsync

Like cp, rsync works on files rather than block devices. The thing about rsync is that it doesn't copy files that are already at the destination. By default, it checks the size and modification time of files, but you can also check the hash (usually this is done when increased security is needed).

Easy to use

The rsync syntax is similar to cp:

Rsync -a /mnt/root /mnt/backup

The -a parameter is often sufficient; it provides what is most needed: recursive copying of directories, saving information about the owner and group, etc. To display detailed information about copying, use the -v switch; be careful with it; you may miss an error message in the data stream. The -x switch ensures that rsync does not go beyond the specified filesystem.

The rsync documentation describes a lot of options. For example, there are those that allow you to copy over SSH, or delete a file from the destination if it was deleted in the source directory.

Smart copying reduces system downtime. We run rsync directly on a running system, the data in which is constantly changing, rsync copies the data, say, within a few hours. Then we switch the system to read-only, run rsync again, now it copies only those files that have changed over these few hours. In a few minutes we have full copy original FS. Downtime was reduced by an order of magnitude compared to offline copying. And in some cases, one online copy will be enough without converting the system to read-only.

Saving previous copies

Strictly speaking, rsync is not a backup tool - it is a synchronization tool. This is important when creating regular copies, because if any important file was deleted in the source working directory, rsync will delete it in the backup copy as well. To improve data security, it is advisable to save old backup copies. However, simply storing multiple copies will require a lot of hard drive space. If there are many copies identical files, then this leads to unnecessary redundancy. This problem can be solved by using hard links.

The point is that in modern file systems(including Ext4), addressing a file is done in two stages: the file name indicates a unique file number (index descriptor or i-node), and the data itself is associated with this number. Any file name is, in fact, a hard link to this number. Consequently, a file (data set) can have several names and be in different directories, and this eliminates redundancy in case of need to duplicate files (after all, a hard link takes up little memory). The data itself is not deleted until the last hard link is requested to be deleted.

A significant limitation is that hard links are only possible within the same file system.

Synchronizing directory contents for the current backup with the source directory:

Rsync \ --archive \ --delete --delete-excluded \ # deleting files that do not exist in the source and excluded files from the backup--progress\ # display information about the progress of the transfer"/home/user/Files/" \ # directory source"/backup/latest/" \ # directory for current backup--exclude = "/Public/" # exclude unnecessary directories

A copy of all files will be created in the /backup/latest/ directory. necessary files and directories from the source and everything unnecessary was removed.

Creating another current backup without redundancy:

cp\--archive\ # save all Additional information about files--link\ # use hard links for files - eliminate redundancy"/backup/latest/" \ # source is the current backup obtained above "/backup/$(date +%Y-%m-%d_%H-%M-%S) /" # destination - directory with date in name for convenience (see man date)

The next time you create a backup, rsync will delete files in the “ /backup/latest/ ” directory that were deleted/excluded/changed in the source directory (changed files are first deleted and then written a new version). However, only the file names (the same hard links) will be deleted; the files themselves (data) will be saved, since hard links were created to them in a neighboring directory with the “cp” command.

Other tools

There are many applications for creating backups in Linux. You can search for the word “backup” in the Center Ubuntu applications to find available in Ubuntu programs for working with backups.

For a corporate environment and simply for fairly large-scale and critical backup tasks, we can recommend understanding one of the most popular and powerful systems backup for Linux called Bacula

By the way, you can also find Russian-language manuals on the Internet.

Parted Magic

Parted Magic is another great one, but paid a distribution kit containing a whole collection of tools for backing up and restoring information, working with disks and partitions, as well as recovering lost data. It supports many file systems, LVM2 and RAID (both hardware and software) and contains tools such as fsarchiver, GParted, the aforementioned Clonezilla, and everything that is required for the methods described in this article. In addition, the distribution includes a web browser and some other additional software. The distribution is translated into several languages, including Russian, and has a full-fledged graphical interface.

LParted

LParted is a full-featured LiveCD designed primarily for working with hard disk partitions (HDDs), permanently deleting or restoring data, and testing hardware. LiveCD based on Lubuntu Linux. LParted is a functional analogue of Parted Magic.

I would like to add here about SystemRescueCD and others

A little more about saving data

    For important data, you can make a mirror partition on two disks. To do this, it is not at all necessary to have a RAID controller and disks of the same size - you can, for example, assemble a mirror from an 80 GB old drive and an 80 GB partition on a new one. Mirroring can be implemented using LVM or software RAID. However, this method is useless if, for example, a voltage of ~220V hits the +5V bus or a meteorite falls on system unit computer.

    IT geeks who have their own server at home can expand the idea of ​​mirroring and use DRBD. The same RAID-1, but hard disks are situated in different computers, which increases reliability.

    Modern convenient solution- backup data to the “clouds”, for example, from using Ubuntu One, Dropbox, http://www.adrive.com/ and others.

    Neither mirroring nor replication on Ubuntu One will save you from accidentally pressing Delete, so in any case, make “classic” backups. And one day, all your hard work and efforts will be rewarded.

ddsimple utility, which is included with most Unix-like operating systems- Linux, FreeBSD, Solaris, etc.
Its purpose is to read data from one device or file and write to another.

dd can be effectively used to create an image of a hard drive, without using commercial utilities like Acronis True Image or Norton Ghost.

Let's assume we have two disks:

  • /dev/sda - the disk whose image needs to be created;
  • /dev/sdb - the disk on which the image will be written.

If necessary, you need to substitute your own values.

The first step is to boot from any available Live-CD disk that has the dd utility and enter command line as a superuser. Create a mount point for backup.

mkdir /mnt/backup

We mount the hard drive on which you want to save the image.

Creating a hard drive image

dd if=/dev/sda of=/mnt/backup/sda.img bs=8M conv=sync,noerror

  • if=/dev/sda - copy the entire hard drive sda;
  • of=/mnt/backup/sda.img - copy to /mnt/backup/sda.img;
  • bs=8M — set the size of the hard drive cache to speed up the copying procedure (otherwise the data will be reset in small portions of 512 bytes);
  • conv=sync,noerror - we indicate to dd the need for bit-for-bit copying and ignoring read errors.

To reduce the size of a hard disk image, you can compress it with any archiver.

dd if=/dev/sda bs=8M conv=sync,noerror | gzip -c > /mnt/backup/sda.img

Recovering a hard drive image

To restore a hard disk image, you must follow the reverse procedure to the procedure for creating this image.

dd if=/mnt/backup/sda.img of=/dev/sda bs=8M conv=sync,noerror

When using compression, you must unzip the image in parallel.

gunzip -c /mnt/backup/sda.img | dd of=/dev/sda conv=sync,noerror bs=8M

Migrating the system to another hard drive

To migrate the entire system to another hard drive, you must set the location of the new drive as the destination.

dd if=/dev/sda of=/dev/sdb bs=8M conv=sync,noerror

Then, if necessary, install booting from this hard drive. Provided that the new hard drive is larger than the old one, there will be an unallocated area on it. It should be marked up and formatted according to existing requirements.

Copy statistics in dd

The main disadvantage of dd is the lack of a visual representation of the statistics of the copying procedure. However, this disadvantage can be easily circumvented. All you need to do is connect to another terminal.

Determine the process number under which dd is running.

Send periodically this process kill command-USR1 process_number_dd .

watch -n 5 kill -USR1 process_number_dd

  • watch -n 5 - execute the command every 5 seconds;
  • kill -USR1 process_number_dd — show copy statistics.

Cons of using dd to create disk images

Everything has pros and cons. dd is a free and very flexible tool, but it can only make a full copy of a volume. Special programs They can only copy data that is stored on disk.

Thus, the volume of a disk image created using dd will be equal to the volume of the disk itself - regardless of how much data is on the disk.



tell friends