Posted in Arch Linux, Linux Basics

Linux Backups (Are They Needed??) – Part 1 – TimeShift

Hey Guys,

To answer the question above, YES. Backups are needed when dealing with any computer operating system. There are many backup solutions out there that conduct backups in different ways. Some do full and incremental backups, some do bare metal type backups while some issue full and incremental system snapshots. Well, in this small post, I want to go over an app that I found for Manjaro and any other linux distro called TimeShift.

http://www.teejeetech.in/p/timeshift.html

https://launchpad.net/timeshift

TimeShift is very similar to the MacOS Timemachine and the Windows built in backup and restore app for snapshots. This app has turned out to be an awesome package and a necessity for my linux system at home. Below is a description of the application from the development page on what this app is. I like the fact that it uses rsync as part of its operations. This makes for a good way to make sure that backups stay up to date and if something happens during the backup or restore process, the rsync side should be able to pick up where it left off.

“TimeShift is a system restore utility which takes incremental snapshots of the system using rsync and hard-links. These snapshots can be restored at a later date to undo all changes that were made to the system after the snapshot was taken. Snapshots can be taken manually or at regular intervals using scheduled jobs.”

Here is another statement that I thought would be appropriate here as well.

“TimeShift is similar to applications like rsnapshot, BackInTime and TimeVault but with different goals. It is designed to protect only system files and settings. User files such as documents, pictures and music are excluded. This ensures that your files remains unchanged when you restore your system to an earlier date. If you need a tool to backup your documents and files please take a look at the excellent BackInTime application which is more configurable and provides options for saving user files.”

To install TimeShift within Manjaro, you can do it one of two ways. Just in case, make sure that you have AUR initiated in the Pamac application:

  • To initialize AUR, open the Pamac application (Add / Remove Software Application)
  • Click on the button in the upper right that looks like three lines on top of each other.
  • Click preferences
  • Give the sudo password if asked
  • Click on the AUR tab
  • Click on Enable AUR Support
  • Select both Search in AUR by default and Check for Updates in AUR
  • Close the window

Now for the TimeShift install Process from Pamac (Add / Remove Software Application):

  • Open the Pamac application (Add / Remove Software Application)
  • Type in timeshift in the search
  • Click on the AUR tab
  • Select timeshift
  • Click Apply
  • A popup will show that there will be dependencies that need to be resolved. Click on the Commit button
  • Enter the sudo password to elevate permission for the installer
  • Just sit back and let the installer finish.
  • Once the install is complete just close the Pamac application
  • Now you have a working version of TimeShift installed and ready to go.

If you choose to do this from a terminal, here you go:

  • Make sure that yaourt is installed by issue sudo pacman -S yaourt
  • Yaourt is the command line app to work with the AUR repository
  • Remember that yaourt complains about running in root. Run from your local account with sudo access.
  • Open a terminal and type sudo yaourt -S timeshift
  • You will need to give your sudo password to elevate for the installation
  • If prompted to edit files, just say no unless you know what you’re doing
  • If prompted to install packages, just say yes
  • Once the installation is complete, you will have a fully operational version of TimeShift

Now that you have a working version of TimeShift installed and ready, go ahead and run the applications. There is an initial configuration process that you can set for your usage. Once that is done, click the create button. This will kick off an initial snapshot process and depending on the size of the hard drive, this process can take a little time. Once the initial process is complete, you can create incremental snapshots to be used as restore points within your system.

Here shows the help page for the timeshift command line application. The application is easy to use as you can probably tell.

 

[kf4bzt@tim-pc ~]$ timeshift –help

Timeshift v17.2 by Tony George (teejeetech@gmail.com)

Syntax:

timeshift –check
timeshift –create [OPTIONS]
timeshift –restore [OPTIONS]
timeshift –delete-[all] [OPTIONS]
timeshift –list-{snapshots|devices} [OPTIONS]

Options:

List:
–list[-snapshots] List snapshots
–list-devices List devices

Backup:
–check Create snapshot if scheduled
–create Create snapshot (even if not scheduled)
–comments <string> Set snapshot description
–tags {O,B,H,D,W,M} Add tags to snapshot (default: O)

Restore:
–restore Restore snapshot
–clone Clone current system
–snapshot <name> Specify snapshot to restore
–target[-device] <device> Specify target device
–grub[-device] <device> Specify device for installing GRUB2 bootloader
–skip-grub Skip GRUB2 reinstall

Delete:
–delete Delete snapshot
–delete-all Delete all snapshots

Global:
–snapshot-device <device> Specify backup device (default: config)
–yes Answer YES to all confirmation prompts
–btrfs Switch to BTRFS mode (default: config)
–rsync Switch to RSYNC mode (default: config)
–debug Show additional debug messages
–verbose Show rsync output (default)
–quiet Hide rsync output
–help Show all options

Examples:

timeshift –list
timeshift –list –snapshot-device /dev/sda1
timeshift –create –comments “after update” –tags D
timeshift –restore
timeshift –restore –snapshot ‘2014-10-12_16-29-08’ –target /dev/sda1
timeshift –delete –snapshot ‘2014-10-12_16-29-08’
timeshift –delete-all

Notes:

1) –create will always create a new snapshot
2) –check will create a snapshot only if a scheduled snapshot is due
3) Use –restore without other options to select options interactively
4) UUID can be specified instead of device name
5) Default values will be loaded from app config if options are not specified

 

—===—===—===—

 

To create a backup from the command line:

  • Type sudo timeshift –create
  • As this is a first time run, it will say “First run mode (config file not found)”
  • This will create the initial full snapshot of the operating system
  • Below is an example of the full system snapshot run

 

—===—===—===—

 

[kf4bzt@tim-pc ~]$ sudo timeshift –create
First run mode (config file not found)
Selected default snapshot type: RSYNC
Selected default snapshot device: /dev/sda1
——————————————————————————
Estimating system size…
Creating new snapshot…(RSYNC)
Saving to device: /dev/sda1, mounted at path: /
Synching files with rsync…

Created control file: /timeshift/snapshots/2017-03-22_11-03-47/info.json
Parsing log file…

RSYNC Snapshot saved successfully (845s)
Tagged snapshot ‘2017-03-22_11-03-47’: ondemand
——————————————————————————
Added cron task: /etc/cron.d/timeshift-hourly
Added cron task: /etc/cron.d/timeshift-boot

 

—===—===—===—

 

I issued the following to list the snapshots on the machine so far

 

[kf4bzt@tim-pc ~]$ sudo timeshift –list
[sudo] password for kf4bzt:
Device : /dev/sda1
UUID : 138fcf48-a8ea-49cd-aa1a-57f2a6a981c7
Path : /
Mode : RSYNC
Device is OK
1 snapshots, 129.5 GB free

Num Name Tags Description
——————————————————————————
0 > 2017-03-22_11-03-47 O

 

—===—===—===—

 

For the sake of testing I reran the create to kick off an incremental snapshot

 

[kf4bzt@tim-pc ~]$ sudo timeshift –create
——————————————————————————
Creating new snapshot…(RSYNC)
Saving to device: /dev/sda1, mounted at path: /
Linking from snapshot: 2017-03-22_11-03-47
Synching files with rsync…
Created control file: /timeshift/snapshots/2017-03-22_11-19-36/info.json
Parsing log file…
RSYNC Snapshot saved successfully (13s)
Tagged snapshot ‘2017-03-22_11-19-36’: ondemand
——————————————————————————

 

—===—===—===—

 

Here is another list with the initial and incremental snapshots in place

 

[kf4bzt@tim-pc ~]$ sudo timeshift –list
Device : /dev/sda1
UUID : 138fcf48-a8ea-49cd-aa1a-57f2a6a981c7
Path : /
Mode : RSYNC
Device is OK
2 snapshots, 129.4 GB free

Num Name Tags Description
——————————————————————————
0 > 2017-03-22_11-03-47 O
1 > 2017-03-22_11-19-36 O

 

—===—===—===—

 

To do a restore of the snapshot just issue the following

 

[kf4bzt@tim-pc ~]$ sudo timeshift –restore –snapshot ‘2017-03-22_11-19-36’
******************************************************************************
To restore with default options, press the ENTER key for all prompts!
******************************************************************************

Press ENTER to continue…

Re-install GRUB2 bootloader? (recommended) (y/n): y

Select GRUB device:

Num Device Description
——————————————————————————
0 > sda ATA ST3160023AS [MBR]
1 > sda1 ext4, 150.6 GB GB
2 > sdb ATA SAMSUNG HD321HJ [MBR]
3 > sdc ATA ST3160023AS [MBR]

[ENTER = Default (/dev/sda), a = Abort]

Enter device name or number (a=Abort): 0

******************************************************************************
GRUB Device: /dev/sda
******************************************************************************

======================================================================
WARNING
======================================================================
Data will be modified on following devices:

Device Mount
——— —–
/dev/sda1 /
Please save your work and close all applications.
System will reboot after files are restored.

======================================================================
DISCLAIMER
======================================================================
This software comes without absolutely NO warranty and the author takes no responsibility for any damage arising from the use of this program. If these terms are not acceptable to you, please do not proceed beyond this point!

Continue with restore? (y/n): y
Mounted ‘/dev/sda1’ at ‘/mnt/timeshift/restore/’
******************************************************************************
Backup Device: /dev/sda1
******************************************************************************
******************************************************************************
Snapshot: 2017-03-22_11-19-36 ~
******************************************************************************
Restoring snapshot…
Synching files with rsync…

Please do not interrupt the restore process!
System will reboot after files are restored

building file list … done
.d..t…… mnt/
.d..t…… timeshift/
>f..t…… var/log/journal/f035dd48f4eb41d0ba36ad8c9879b1bd/system.journal
.d..t…… var/log/timeshift/

sent 24,747,157 bytes received 49 bytes 16,498,137.33 bytes/sec
total size is 7,407,772,695 speedup is 299.34

Re-installing GRUB2 bootloader…
Installing for i386-pc platform.

Installation finished. No error reported.

Updating GRUB menu…
Generating grub configuration file …
Found background: /usr/share/grub/background.png
Found Intel Microcode image
Found linux image: /boot/vmlinuz-4.4-x86_64
Found initrd image: /boot/initramfs-4.4-x86_64.img
Found initrd fallback image: /boot/initramfs-4.4-x86_64-fallback.img
Found Windows 7 (loader) on /dev/sdb1
Found memtest86+ image: /boot/memtest86+/memtest.bin
done

Synching file systems…
Rebooting system…
Failed to read reboot parameter file: No such file or directory
Rebooting.

 

—===—===—===—

—===—===—===—

 

While installing within Ubuntu Mate 17, I created the following screenshots to show what TimeShift should look like from the beginning. The first screenshot starts the configuration of Timeshift. I have been leaving this as RSYNC as I find it works better when creating backups for your data.

 

 

You need to choose a drive to place the snapshots onto for storage. As you can see, my laptop only has the one drive so I selected sda1 to store the snapshots.

 

 

Now, we have to choose how we want the snapshots to be complete. The default is Boot at 5 and Daily at 5. I added Weekly at 3 just to play around with the settings. Keep in mind that your machine has to be powered on for this work or not in sleep mode.

 

 

The next screenshot is for creating Includes and Excludes but if you want a full system snapshot them leave this at default. Keep in mind that the snapshots change only if there are changes to the file system. This does not include the items within the users home folders. You will need an app such as Back In Time to backup the home folders and content.

 

 

The screenshot shown below show a snapshot in place.

 

 

And the final screenshot shows the information about the snapshot.

 

Leave a Reply

Your email address will not be published. Required fields are marked *