How to manually backup your config files

##How to manually backup your config files##

###Skills included in this Tutorial###
a. open a terminal
b. use Command Line Interface (CLI)
c. copy a file
d. compare contents of two files
e. verify date and time of a file
f. replace system file
####Background####
I've been using a manual update process with my 2 machines. On my HP desktop today I was prompted to keep my existing or update /etc/systemd/system.conf. The default was to replace it. I decided to replace it but not before I made a copy of the existing. After the update completed I checked the difference using diff command. There were no differences on this machine.
Note this is not from scratch Ubuntu Mate 16.04 install, but rather an Ubuntu 16.04 fresh install with MATE desktop added.
####Reasoning####
There are occasions when replacing files might undo changes you’ve intentionally made to your system – especially if you’re 2 years into a LTS release and the change(s) you made was just after the initial release. Assuming you don’t remember changes to the file and want to insure that you can maintain the changes going forward I suggest making a backup of the existing file BEFORE you click on replace. After the system is finished then you can examine the 2 files for differences.

The example file /etc/systemd/system.conf is a critical part of your system and is an integral part of systemd. Systemd is a system and service manager for Linux. It activates starting services and offers on-demand starting of deamons (a computer program that runs as a background process).


####Procedure####
Since the exact path of the file to be replaced is provided in the warning, using a terminal command will prove expedient.
Access a terminal using simultaneous key press Crtl-Alt-t which results in a command prompt

####Commands####
In the examples below we will make a backup copy of the system file to be replaced by the software upgrade. We will compare the original file to the new file. We will, if required, replace the new file with the existing one. You will have to adapt the exact command syntax to your situation by replacing the bold characters to match your needs.

Using a simple command will duplicate the file to a place of your choosing. More than likely the file will be in a directory that, using your normal assigned privilege, will not have the ability to create a new file. Therefore I suggest duplicating the file to you home directory using this command
cp /etc/systemd/system.conf system.conf.org
#####Command explanation#####
cp is short for copy
/etc/systemd/system.conf full path to target
system.conf.org appended .org to indicate this is the original

You may check the difference in the files after the system finishes by using another simple terminal command. I suggest using a two step approach where the first is a simple test of ANY differences
command to compare two files step
diff -q /etc/systemd/system.conf system.conf.org
diff compares two files, -q produces a brief output

if no difference exists a command prompt will be returned – the software update replaced the file and there were no differences - you’re done!


if there are differences you will see screen below

when files differ step 2 is indicated using the diff command without -q to examine the differences
diff /etc/systemd/system.conf system.conf.org

The command will return differences where the characters < and > indicate
> lines from system.conf.org
< lines from /etc/systemd/system.conf

this indicate there were 3 changes to system.conf.org
1. added text here
2. changed this line
3. added line here

###Decision###
At this point you will decide to either keep the system replaced file or use your original. For the keep system file decision you need to do nothing as it’s already been replaced.

For replacing the new file with the original for this example assume you’ve closed the terminal and at a later time you wish to return your original to operation. Make a copy of the new file in case you need it later; open a terminal session using Crtl-Alt-tand enter these two commands
sudo cp /etc/systemd/system.conf /etc/systemd/system.conf.new
ls -l /etc/systemd/system.conf.new

*these commands copy the file and append .new for identification and verify the file >was copied to the correct directory us the ls (list) command
*sudo elevates your privilege to admin because this command copies the just placed >file in a protected directory. Using sudo requires your password – when you type it - there will be no indication that you’re typing – hit return once you’ve entered your password.
*ls lists information about files; -l specifies long list format


file type and permissions, group and individual owner, date file created or edited >are all displayed when using the -l (long)

File {type, permissions, link}    owner    group    size    last access    full path
-rw-r--r-- 1                      root      root    1537    May 12 05:39    /etc/systemd/system.conf

now we copy the original file copied into your directory and replace the new file that software updater placed sudo cp system.conf /etc/systemd/system.conf

     `_Note: I appended .tst to above example to avoid changing my system._`

I suggest closing any open applications at this point an rebooting your machine.


###Skills Review###
a) open a terminal Crtl-Alt-t
b) use Command Line Interface (CLI) vs Graphical User Interface (GUI)
c) copy a file using the cp command
d) compare contents of two files using the diff command
e) verify date and time of a file us the ls command
f) replace system file using sudo preceding a commands

##More Information and Practice##

Linux file permissions explained
https://www.linux.com/learn/understanding-linux-file-permissions
http://linuxcommand.org/lts0070.php

More information is available for c through f by typing man in a terminal followed by the command of interest man cp shown

Pressing down arrow advances 1 line
Pressing space bar advances 1 page
Pressing q quits man

These commands can be practiced on a system file copied to your directory twice, one modified, and compared to on another.

3 Likes

I guess this needs a revision :confused:

Thanks for the catch, good eyes!
I have made the correction

hehe I am using an awesome tool :telescope: :stuck_out_tongue:

Just one thing to mention. I’m not really sure if diff will always work in the sense that not all file systems storage the same time stamps like last access, does it matter or it doesn’t?

diff actually reads the file contents and displays the differences … try making a copy of an old file, then make changes to the file and save it with another name, run diff on the 2 new files, and then the original against the newly changed file to see how it works.

1 Like