Institute of Computer Science
  1. Courses
  2. 2017/18 spring
  3. System Administration (LTAT.06.003)
ET
Log in

System Administration 2017/18 spring

  • Home
  • Video Lectures
  • Practicals
  • Exam
  • References

Backup you VM

Congratulations, you finally have configured System Administration 2018 course services on your personal server and in order to make sure nothing bad happens to it we should make a backup of it. There are no good all in one free backup solution available for Linux especially if you are interested of making a backup from running (live / production) server / machine. You can read a overview of how backup works from https://en.wikipedia.org/wiki/Backup and https://help.ubuntu.com/community/BackupYourSystem . You have your course server in University of Tartu ETAIS public cloud but wouldn't it be nice to have a copy of it running locally in your Virtualbox for exam preparation and later use. Therefore following backup solution is quite custom and includes manual labor, but gives you better control and learning how similar more automatic processes and software works under the fancy user interface.

Disclaimer! We will keep your personal System Administration 2018 course Virtual Machines running till Sunday 10th of June 2018. Therefore make sure if you want to have a copy of your machine to use following manual before we turn it off and remove from ETAIS.

Create and restore VM backup in ETAIS

How to create and restore backup in ETAIS is diescribed in following video:

Create a new backup in ETAIS and restore your VM from backup.

  • Try flipping "old" IP from original machine to new machine created from backup.
    • Update IP-s in bind config /etc/bind/named.conf.options
  • Do not forget to change your IP back after you have finished testing!
  • PS! Please be kind to ETAIS resources and keep only resources in use active. Meaning:
    • Delete old backups
    • Keep only one Virtual machine running

NB! Old backups created before 15th of April are unfortunately broken and cannot be successfully restored through ETAIS interface. Therefore in order to save space in cloud delete old backups.

Create a backup from Linux Virtual Machine running in cloud

Before you continue lets have a look at your space usage in cloud environment

  • # df -h

We will be using tool called TAR you can read more about it from man tar and https://help.ubuntu.com/community/BackupYourSystem/TAR .

Backup your machine to University of Tartu nextCloud (used to be called ownCloud) your personal storage space 1. First lets make a one big tar file with all needed bits and configuration files. PS! It will take around 10 min so feel free to read all the links mentioned earlier that you probably skipped.

 # tar -cvpzf /tmp/backup-$(date '+%d-%b-%Y').tar.gz --exclude=/tmp --one-file-system  /
 # tar -cvpzf /tmp/data-$(date '+%d-%b-%Y').tar.gz /mnt/vdb1

2. Now lets upload the backup file to University of Tartu ownCloud server. PS! Use your University of Tartu username and password for authentication.

 $ curl -u <ut_login_name> -X MKCOL "https://owncloud.ut.ee/owncloud/remote.php/webdav/SA-backup/"
 $ curl -u <ut_login_name> -T /tmp/data-30-Apr-2018.tar.gz "https://owncloud.ut.ee/owncloud/remote.php/webdav/SA-backup/"
 $ curl -u <ut_login_name> -T /tmp/backup-30-Apr-2018.tar.gz "https://owncloud.ut.ee/owncloud/remote.php/webdav/SA-backup/"

It might take few minutes but soon the command line would be released indicating the completion of upload. PS! No output is good and mean there was no error.

In order to check if backup files are indeed in University of Tartu ownCloud just try to log into it and check if the file is available online https://owncloud.ut.ee/ (Also verify that the size is correct!)

Lets create a new Virtual Machine in VirtualBox

So now we have copy of our machine data available in our ownCloud, but lets see how to use in order to restore a machine in case a disaster. tar does not create a full copy of hard disk nor virtual machine description as we only created file system level backup because you did not have full access to your virtual machine. In case you could turn off machine block level copy could be achieved with dd command, but then you must use same size or bigger hard disk to restore.

So First lets create a new Virtual Machine in your personal machine's Virtualbox and lets try to restore our System Administration course personal server.

  • For VirtualBox users:
    • Open the VirtualBox application, and click New Button
      • Give a new VM a name SA-server-backup
      • Choose a type Linux
      • Choose version Debian (64-bit)
        • If 64-bit is not listed you probably dont have Virtualization Technology needed to virtualize 64-it machines enabled in BIOS or your computer is too old. https://en.wikipedia.org/wiki/Virtualization
      • Click Next
      • Specify amount of memory 2048MB, as this will be enough for testing purposes
      • Click Next
        • Select Create a virtual hard disk now
      • Click Next
        • Select VDI (VirtualBox Disk Image)
      • Click Next
        • Select Dynamically allocated
      • Click Next
        • Set 8 GB as size
      • Click Create
    • The newly created VM should be visible in the VM list (in the left in VirtualBox main window you should see SA-server-backup icon)
    • Right-click on it and select Settings
      • Go to System -> Processor tab -> select 2 CPU cores and Enable PAE/NX -> Acceleration tab -> Verify that Enable VT-x/AMD-V is marked -> Click OK.
      • Go to System -> Storage tab -> Left click on Controller: SATA -> Left click on right most icon Add disk -> Add second 1 GB dynamically expanding VDI disk.
    • Double-click on SA-server-backup VM in the list of VMs
    • During the first boot, the VM will ask to provide an ISO image to boot from
      • Provide the ISO file of the live version of Debian 9.4 which can be downloaded from here https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-9.4.0-amd64-xfce.iso.

As a result the VM should start Live CD boot process

  • the new window will appear illustrating VM's VGA output
    • For releasing the mouse pointer use right Ctrl key
  • you should see the boot menu page with possible boot options

In order kill/reset the running instance:

  • In menu File of the running VM's window
  • Select Close
  • Chose Power off ...

Next time you need to run the VM you can just double-click the corresponding icon in the VM list

After you have started the VM a Debian Live boot windows should appear:

  • Please select Debian GNU/Linux Live (kernel 4.9.0-6-amd64) and hit Enter
  • The standard boot process will take place and bring to a login prompt:
    • The default user for any Debian live is user with password live

Now we are ready to boot into Debian Live and start manual restoration of server from backup!

Restoring our System Administration course server using Debian Live shell

The first thing we need to do is to switch to root shell in order to have access to utils like:

  • fdisk, mkfs.ext4, mkswap, tune2fs, apt, mount, nano, vi, debootstrap (etc.)
  • ... which we will use to setup the OS up.

'Changing to root shell in Live Normally you should do this over su - in live however it is not critical to avoid sudo, so we do this like:

  • sudo su -

And afterwards we may notice our user shell sign $ changed # (a sign of a root shell).
Now we must partition and formatting our HDD.

Partitioning virtual HDD (DOS or GPT) >>tocheck>> First of all make sure we have HDD in our system at all:

  • # fdisk -l or
  • # lsblk
  • ... should give us an information about attached hard drives and partitions
    • We should see /dev/sda (the first hard drive) empty with 8 GiB of free space.

Enter the fdisk interactive partitioning tool:

  • # fdisk /dev/sda
  • Now here we operate the the using keys, for example key m gives a manual of all other keys to control fdisk
  • Lets create a fresh DOS partition table issuing o
  • Now click n to create a first partition table
    • It will ask to select primary/extended, in our setup we will rely on primary partitions only (we will only have 2 of them)
    • Now confirm the 1 for partition number and 2048 for the offset of first sector
    • Next select the last sector by giving an amount of desired free space +2G
  • Now you can see the first partition was created, you can check it using p key.
  • Next we give a type for a first partition which we make a swap area of our OS.
    • Hit t for specifying the type, and you may have list of all types using L
    • Enter the code for type Linux swap / Solaris and hit Enter
  • Now create another primary partition, allocating the remaining free space for it and giving it a type Linux (code 83, which is default anyway).
    • In order to make it use all the remaining space - in the dialog, when asked about the last sector just leave the default value as it is (default value is the last possible sector to allocate on HDD).
  • Save the partition table using w key which will also terminate the fdisk and refresh the partition partition tables in kernel.

Formatting newly created partitions
Format the first partition into swap area using command. Flag -L adds a label to the partition.

  • # mkswap -L SWAP /dev/sda1 .

Format the second partitions into ext4 using command

  • # mkfs.ext4 -L ROOT /dev/sda2 .

Adding created partition to the file tree
The newly formatted ROOT file system is not yet added to the file tree, hence it is impossible to create any files in there. First we need to add the file system to the system file tree by specifying a directory for it (mounting a file system to a directory). Create a new directory under /mnt named NewRoot. Mount the root partition (by its label) to the newly created directory,

  • # mount -L ROOT /mnt/NewRoot .

Repeat the process for data partition. (you have to format it as ext4 and create a folder at /mnt/vdb1 first)

  • # mount -L DATA /mnt/vdb1 .
  • # lsblk .

Restoring from ownCloud

Now we have a new virtual machine and empty hard disk ready to restore VM from backup to it.

  • Lets download data from ownCloud...
 # apt update
 # apt install curl
 # cd /mnt/NewRoot
 # curl -u <ut_login_name> -O "https://owncloud.ut.ee/owncloud/remote.php/webdav/SA-backup/backup-30-Apr-2017.tar.gz"
  • IF the download fails or gets interrupted you can continue where it left last time with -C- parameter # curl -C- -u ut_login_name -O "https://owncloud.ut.ee/owncloud/remote.php/webdav/SA-backup/backup-30-Apr-2018.tar.gz"
  • now lets unpack data from backup file
 
 # tar -xzvf backup-30-Apr-2018.tar.gz

Now lets restore data partition files:

 # cd /mnt/NewRoot
 # curl -u <ut_login_name> -O "https://owncloud.ut.ee/owncloud/remote.php/webdav/SA-backup/data-30-Apr-2017.tar.gz"
 # cd /
 # tar -xzvf /mnt/NewRoot/data-30-Apr-2018.tar.gz
 # ls /mnt/vdb1/data

If you executed all commands in correct folders now you should have ro and rw folders listed in /mnt/vdb1/data

Change root into old Debian
Currently we have just one Debian environment running on Linux kernel. What we do next is that we first share the kernel specific directories of the Debian Live with our new Debian. In file tree we will have to now link existing kernel directories into the new root directory. Navigate to new Debian root first:

  • # cd /mnt/NewRoot

Next do linking using --bind option of a mount commands:

  • # mount --bind /dev dev/
  • # mount --bind /proc proc/
  • # mount --bind /sys sys/
  • # mkdir /mnt/NewRoot/tmp
  • # mount --bind /tmp tmp/

Now run command:

  • # chroot .

Which will change the top level directory / of Live Debian into /mnt/NewRoot of our new Debian. Now the active environment is not anymore the one of Debian Live but the one of backup Debian.

As our machine was run in cloud and some of its configuration was also updated by cloud provider we have to disable that functionality as otherwise it will wait for its timeout at boot and it will take very long time. Change file /etc/cloud/cloud.cfg.d/90_dpkg.cfg

  • It says you should run command dpkg-reconfigure cloud-init instead
  • # dpkg-reconfigure cloud-init

Leave only last one none marked. After succesfull edit it should look like this ...

Before we can boot from newly created disk we need to fix /etc/fstab and GRUB bootloader. Instead of specifying long ID we recommend using labels like shown in the picture

Finally lets restore GRUB MBR records

 # grub-install /dev/sda
 # update-grub
 # exit
  • Reboot and remove the live-cd from the cd drive of Virtualbox so it would boot from hard drive
  • Check if you can log in and all the services are started!
    • Remember that Virtualbox Network is different so not all the services might function properly (i.e. you cannot reach teacher.est neither any other .est machines).
    • We do recommend using bridge mode in Virtualbox or NAT port forwarding so your host (Windows, iOS, Ubuntu, ect) machine would easily also be able to connect to Virtual Machine

NB! Public WiFi networks do not allow bridge mode (i.e. eduroam ut-public)

  • Add manual DNS records to C:\Windows\System32\drivers\etc\hosts or /etc/hosts file depending of your host to solve your domain records.
 192.168.X.Y www.<yourdomain>.est
  • Now try to access Virtual your machine Apache web-server from host operating system web-browser

CONGRATULATIONS ALL LABS COMPLETED ...
NOW START LEARNING for Exam.

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment