Over a million developers have joined DZone.

How to Sync Your Data When You Restore a VirtualBox Snapshot [Code Snippet]

Learn how to restore your VMs with the current time with this simple script.

· Mobile Zone

This article is about synchronizing and updating the clock in your guest Linux VM after you restore a VirtualBox snapshot.

When you create a VirtualBox snapshot, it’s essentially a photo taken and frozen in time. All bits, including the date and time, are frozen in that instant. When you restore a snapshot, the Linux guest VM system is restored back to that snapshot (again, including the date and time). However, this may not be desired all of the time, especially if the purpose is to restore the configuration and settings to an earlier time and you want to roll forward the clock on the VM to the present instance.

The outlined steps below can also apply to other virtual hypervisors such as Qemu, VMWare, Amazon S3 images, etc. (Essentially, they can apply wherever you may have a CentOS or Red Hat Linux Virtual instance. Additionally, with slight modifications, the same can be applied to any Linux guest hypervised image.)

Below are a few simple steps you can take to reset the clock:

Here are the steps that you should perform before you create a VirtualBox snapshot:

# Install ntp service 
yum -y install ntp
# Turn it on so that it starts up automatically on reboot
chkconfig ntpd on
# Point it to your nearest internet accessable NTP server available around the globe for time-services 
ntpdate pool.ntp.org
# Manually start it up and ensure that it comes up
service ntpd start

Now, you can take your VirtualBox snapshot as needed.

When you restore a snapshot, you should do the following after the snapshot is restored:

# After snapshot restore, run 
ntpdate pool.ntp.org

And that’s it! Your date and time should now be updated. However, all of the other settings and modifications you have done will be restored to their former glory!

You may be wondering what NTP is. NTP stands for Network Time Protocol, and it is an Internet protocol that is used to synchronize the clocks of computers to some time reference.

Topics:
s3 ,virtualbox ,mobile ,vm disk image

Published at DZone with permission of Venkatt Guhesan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}