Welcome!
Forum users

Current releases
--MX-23 release info here
--Migration information to MX-23 here
--antiX-23.1 (Arditi del Popolo) release info here

Important information
--If in starting your system it boots to an unwanted Desktop, right click desktop, then select leave and logout. At the
login screen there is a session chooser at the top of the screen.

News
-- MX Linux on social media: here
-- New Forum Features, Marking Solved and Referencing a User: here

MX Linux Backup and Restore your running system

Topics relating to MX Docs and MX Videos
Message
Author
asinoro
Posts: 152
Joined: Mon Feb 22, 2016 12:26 pm

MX Linux Backup and Restore your running system

#1 Post by asinoro »

This guide might look long, but in reality there are 3 commands at Method C who do the job.
1- One to backup Step 1.
2- One to restored Step 2.
3- One to restore from live medium or other Linux operating system Step 5.
And the Automatic Backup at Step 6

Method A
The best backup is to have a stored image:
https://mxlinux.org/make-snapshot-installed-system

Method B
Or to clone the entire partition of you system:
https://mxlinux.org/forum/viewtopic.php?t=39567

Method C
Another option after trying many different ways with rsync, I decided that the best way to backup and restore the running system can be achieved with the cp command together with the help of the rsync.
The cp command as root copies all the data and places at the storage but do not replaces the old stored data.
This limitation will be corrected with the use of rsync, where the rsync will delete all the data at the storage that do not exist in the source.
The same will be with the restore where it will be deleted everything that doesn’t belong at the backup so, your system will be exactly how it is at the backup.

Always a successful backup it can be, by minimizing the activities of the running system. When you see to be dropped the network stop any activity from your side and leave the program to do its job

Step 1
Backup System

In this example as network is taken eth0 where the commands are.
To stop:

Code: Select all

nmcli con down id 'Wired connection 1'
To start:

Code: Select all

nmcli con up id 'Wired connection 1'
For WiFi you change:
To stop:

Code: Select all

nmcli radio wifi off
To start:

Code: Select all

nmcli radio wifi on
Run the the modified command of yours for the rsync and pc command separated by semicolon (;) :

Code: Select all

sudo nmcli con down id 'Wired connection 1' ;  rsync  -axv --progress --stats --update --delete-before  --ignore-errors --exclude={/dev/*,/proc/*,/sys/*,/var/tmp/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found/*,/.gvfs/*,}  /   /media/xxxx/xxxx/PCBACKUP/ ; cp -uvaxT /  /media/xxxx/xxxx/PCBACKUP/  ; nmcli con up id 'Wired connection 1'
Where for rsync:
rsync is the command.
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X).
-x, --one-file-system don't cross filesystem boundaries.
-v, --verbose increase verbosity.
--progress show progress during transfer
--stats give some file-transfer stats
--update skip files that are newer on the receiver
--delete-before receiver deletes before transfer, not during
--ignore-errors delete even if there are I/O errors
--exclude= All the folders that can interfere with the system backup.

Where for cp:
cp is the command.
-u, --update copy only when the SOURCE file is newer.
-v, --verbose explain what is being done.
-a, --archive --preserve=all.
-x, --one-file-system stay on this file system.
-T, --no-target-directory treat DEST as a normal file.

The (/) root is the File System.
/media/xxxx/xxxx/PCBACKUP, the stored folder, you choose your own.

The first backup will take time according your stored data on your system, next ones will be more fast thanks to --update, -u option.

Step 2
System Restore

Attention! Before your restore the backup close all running programs.

Run the follow command after modified according your data and change it, if it is for eth0 or WIFI:

Because there is a type of bug the command is modified to delete first the dpkg folder and /var/log/ of the system. Also after the restore updates the database.

Code: Select all

sudo nmcli con down id 'Wired connection 1' ; rm -r /var/lib/dpkg/ ; rm -r /var/log/ ;  rsync  -axv --progress --stats --update --delete-before  --ignore-errors --exclude={/dev/*,/proc/*,/sys/*,/var/tmp/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found/*,/.gvfs/*,}   /media/xxxx/xxxx/PCBACKUP/    / ; cp -uvaxT    /media/xxxx/xxxx/PCBACKUP/    / ; nmcli con up id 'Wired connection 1'; updatedb
Step 3
If your restore kernel from the backup then run:

Code: Select all

sudo update-grub
Step 4
There is one issue which appears often after the restore of kernel. When you boot maybe will not load the OS and it will appear a message with “initramfs”.

Don't worry! From live, DVD, USB, or other Linux OS, open the terminal.

Code: Select all

sudo blkid
Find your OS and replace the command with yours, where sdxx your partition, to automatically repair the filesystem:

Code: Select all

sudo fsck -a /dev/sdxx
or

Code: Select all

sudo fsck -y /dev/sdxx
Reboot and you will access your OS.

Step 5
System Restore from Live Medium or other Linux OS

Because of the live restore, there is the possibility something to go wrong during the restoration of the backup, then the only option is, to have exactly the data of the backup into your system.
To do that, you have to be at live DVD, USB or another Linux OS and to run the following commands:

First it removes all the data from your System Folder with ( rm -r ) in this example the name is rootMX161, which is the default during installation.
Then you run the pc command from storage backup, where it is here the PCBACKUP, to your system folder where again here it is rootMX161. Of course you will change the names with yours.

Run the command, to find your OS, where now it is rootMX161:

Code: Select all

sudo blkid
And after replace and run the command to fit with yours:

Code: Select all

sudo su
Then

Code: Select all

rm -r /media/xxxx/rootMX161/* ; cp -uvaxT  /xxxx/xxxx/PCBACKUP/  /media/xxxx/rootMX161/  
To be sure that everything is ok run the command fsck as it is at Step 4.

Step 6
Automatic Backup

This is the manual way, what nicer the automatic backup, for that you can follow the tutorial as how to use gnome-schedule which is already installed at MX 16:
https://mxlinux.org/forum/viewtopic.php?t=39567

Where as a command you will use the modified of yours:

Code: Select all

nmcli con down id 'Wired connection 1' ;  rsync  -ax --progress --stats --update --delete-before  --ignore-errors --exclude={/dev/*,/proc/*,/sys/*,/var/tmp/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found/*,/.gvfs/*,}  /   /media/xxxx/xxxx/PCBACKUP/ ; cp -uvaxT /  /media/xxxx/xxxx/PCBACKUP/  ; nmcli con up id 'Wired connection 1'
References
1- With this system backup it combines the flexibility of rsync with the stability of the coreutil cp.

2- It can run a backup from a running system minimizing the possibilities to go wrong, by stopping and restarting network. This option it can be deactivated with private risk.

3- There is not limitation of the stored data.

4- The stored data are secure because the folder is made by the root and are visible and accessible from the user.

5- The time of the backup except the first one will be fast thanks to the options –update and -u of the commands.

6- It will restore the live system fast, and more reliable from a live medium or other Linux OS.

7- With the gnome-schedule it can do automatic several different backups, I suggest one in a step of 15 days and another one, daily. Two automatic backups are better than one.

8- This backup keeps all the information of your system, partitions, grub, etc, where when your restore it from a live medium or another Linux OS, your system will be exactly how it was the time of the backup.

9- The quality of the backup it is equal to dd, because cp it is also coreutil, the difference it is that stores only the data and not all the sectors of the partition.

10- Nothing is perfect any suggestions that improves is always welcome, and because nothing is more important in the computer world than our operating system.

Enjoy the Linux flexibility and simplicity.
Last edited by asinoro on Tue Oct 24, 2017 5:03 am, edited 20 times in total.
If your case is solved, edit [Solved] to your initial post title to help other users.

Fix your Grub

User avatar
Adrian
Developer
Posts: 8230
Joined: Wed Jul 12, 2006 1:42 am

Re: MX Linux Backup and Restore your running system

#2 Post by Adrian »

I had good success with rsync, what I like about it it can do incremental updates, I usually do this:

Code: Select all

rsync -av /mnt/sda1/ /mnt/backup
To make sure it deletes the file on target after the update:

Code: Select all

rsync -av --delete-after /mnt/sda1/ /mnt/backup

asinoro
Posts: 152
Joined: Mon Feb 22, 2016 12:26 pm

Re: MX Linux Backup and Restore your running system

#3 Post by asinoro »

With rsync when is about to backup the main File System you must exclude several other system folders and mount points. It does very well with home folder but not with the File System.
If your case is solved, edit [Solved] to your initial post title to help other users.

Fix your Grub

User avatar
Adrian
Developer
Posts: 8230
Joined: Wed Jul 12, 2006 1:42 am

Re: MX Linux Backup and Restore your running system

#4 Post by Adrian »

That's true, but it depends what you want to use it for and how many mount points you have (you can use -x to copy only the files from one file system, it excludes mount points).

skidoo
Posts: 753
Joined: Tue Sep 22, 2015 6:56 pm

Re: MX Linux Backup and Restore your running system

#5 Post by skidoo »

"With rsync [...] you must exclude several other system folders and mount points."
Same as with your cp proposal, you would do that ahead of time, one time ~~ by drafting a custom commandline containing desired command switches/options.
Also, I believe that exclusion of "several other system folders" is a BestPractice.

No, I would not have full confidence in a "backup" fileset created via cp.
cp considers difference based on date, is blind to any partial/corrupt files, vs rsync which considers checksums.
Another consideration: rsync easily handles differential backups (can remove from destination any items which are now-absent at source)

asinoro
Posts: 152
Joined: Mon Feb 22, 2016 12:26 pm

Re: MX Linux Backup and Restore your running system

#6 Post by asinoro »

Because the friend of good is better, I improved this guide.
If your case is solved, edit [Solved] to your initial post title to help other users.

Fix your Grub

asinoro
Posts: 152
Joined: Mon Feb 22, 2016 12:26 pm

Re: MX Linux Backup and Restore your running system

#7 Post by asinoro »

It was upgraded to two commands one for backup and one for restore.
There is one gui for dd if we can modify with the commands of backup and restore will be a very nice gui backup and restore for MX Linux!

https://launchpad.net/gdiskdump
If your case is solved, edit [Solved] to your initial post title to help other users.

Fix your Grub

User avatar
penguin
Posts: 260
Joined: Wed Jan 04, 2017 3:15 pm

Re: MX Linux Backup and Restore your running system

#8 Post by penguin »

Code: Select all

https://forum.mxlinux.org/viewtopic.php?f=104&t=41293&start=10#p419243
It is a simple method I used to transport a running MX Linux to another drive.
More info for rsync you van find here :

Code: Select all

https://wiki.archlinux.org/index.php/Rsync#As_a_backup_utility
And probably the the simplest way to backup/restore your MX Linux Backup is qt4-fsarchiver utility.I never tried this utility on a running MX Linux.So; I suggest: Start your computer with an bootable MX Linux usb and use qt4-fsarchiver to or restore backup your Mx Linux to/from somewhere.
Hope it helps.

User avatar
Adrian
Developer
Posts: 8230
Joined: Wed Jul 12, 2006 1:42 am

Re: MX Linux Backup and Restore your running system

#9 Post by Adrian »

Also there's Clonezilla if you want to clone the entire drive or a partition, you can install it in MX, it can be used to clone Windows and Linux partitions.

asinoro
Posts: 152
Joined: Mon Feb 22, 2016 12:26 pm

Re: MX Linux Backup and Restore your running system

#10 Post by asinoro »

The guide of the backup took its final shape! Additionally to restore from a live medium or other Linux OS.
If your case is solved, edit [Solved] to your initial post title to help other users.

Fix your Grub

Post Reply

Return to “Documentation and videos”