NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.
Forum Discussion
JMehring
Feb 14, 2014Apprentice
How to run snapper (filesystem restore) on OS6
Snapper (http://snapper.io/) is a tool for Linux filesystem snapshot management. Apart from the obvious creation and deletion of snapshots, it can compare snapshots and revert differences between snapshots. In simple terms, this allows root and non-root users to view older versions of files and revert changes.
Snapper can create snapshots "tagged" as pre or post snapshots. This is handy when it comes to system upgrades. Using NUMBER_CLEANUP="yes" those can get cleaned up after a configurable number of snapshots using the number cleanup algorithm.
More info snapper can be found at http://snapper.io/ and https://wiki.archlinux.org/index.php/Snapper. I suggest you look at some of the videos on the main site.
I have included a modified apt-get wrapper to create pre and post snapshots called snp (Original source https://gist.github.com/erikw/5229436)
Please follow the configuration instructions closely since the default installation configuration will run a snapshot every hour and fill up the root partition very quick. I set it for manual use only, but you should still be careful not to fill up the root partition. Really (delete snapshots after use) or maybe tell us how to grow the root partition :)
It seems like snapper is already included with OS6.1.6, maybe earlier versions too, so all we need to do is configure it for use.
Initial configuration of snapper:
Edit /etc/snapper/configs/root to reflect the following configuration. TIMELINE_CREATE="no" disables automatic timeline snapshots and we set all the TIMELINE_LIMIT_* to 0 just to be extra careful.
Create a log directory for snp. snp is the apt-get wrapper:
Create a file and save it named /usr/local/bin/snp and enter the following script
Make sure to give snp execute permissions
Configuration is now complete, so lets do some tests!
Show curent snapshot list
Lets create a manual snapshot now
For testinf, we are not going to install a package via apt-get since I do not know what repositories you have, so we will just use apt-get update as an example
Now lets check out our snapshots again
Lets see what was modified.
Lets remove the update. Snapper does not tell the kernel about the change, so you must either do so yourself or reboot if required.
REMEMBER, lets not keep any of these snapshots around for any length of time since we do not want to fill up the / root partition since that would be really bad!
So lets now delete our snapshots we used for testing
"Thanks to Snapper, you can mess up system configuration changes or package installations or updates without having to restore from an old backup and risking to lose some files. Just revert to the snapshot before your problematic change and you’re fine." Linux User & Developer Magazine
Snapper can create snapshots "tagged" as pre or post snapshots. This is handy when it comes to system upgrades. Using NUMBER_CLEANUP="yes" those can get cleaned up after a configurable number of snapshots using the number cleanup algorithm.
More info snapper can be found at http://snapper.io/ and https://wiki.archlinux.org/index.php/Snapper. I suggest you look at some of the videos on the main site.
I have included a modified apt-get wrapper to create pre and post snapshots called snp (Original source https://gist.github.com/erikw/5229436)
Please follow the configuration instructions closely since the default installation configuration will run a snapshot every hour and fill up the root partition very quick. I set it for manual use only, but you should still be careful not to fill up the root partition. Really (delete snapshots after use) or maybe tell us how to grow the root partition :)
It seems like snapper is already included with OS6.1.6, maybe earlier versions too, so all we need to do is configure it for use.
Initial configuration of snapper:
snapper -c root create-config /
Edit /etc/snapper/configs/root to reflect the following configuration. TIMELINE_CREATE="no" disables automatic timeline snapshots and we set all the TIMELINE_LIMIT_* to 0 just to be extra careful.
# create hourly snapshots
TIMELINE_CREATE="no"
# limits for timeline cleanup
TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="0"
TIMELINE_LIMIT_DAILY="0"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"
Create a log directory for snp. snp is the apt-get wrapper:
mkdir /var/log/snp
Create a file and save it named /usr/local/bin/snp and enter the following script
#!/usr/bin/env bash
# Runs a command wrapped with btrfs pre-post snapshots.
log_path="/var/log/snp"
date=$(date "+%Y-%m-%d-%H%M%S")
log_file="${log_path}/snp_${date}.log"
# Log stdout and stderr. Reference: http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to-log-file-from-within-bash-script-itself
exec > >(tee -a "$log_file")
exec 2> >(tee -a "$log_file" >&2)
cmd="$@"
snapshot_nbr=$(snapper create --type=pre --cleanup-algorithm=number --print-number --description="${cmd}")
echo -e "> New pre snapshot with number ${snapshot_nbr}."
echo -e "> Running command \"${cmd}\"."
eval "$cmd"
snapshot_nbr=$(snapper create --type=post --cleanup-algorithm=number --print-number --pre-number="$snapshot_nbr")
echo -e "\n> New post snapshot with number ${snapshot_nbr}."
Make sure to give snp execute permissions
chmod a+x /usr/local/bin/snp
Configuration is now complete, so lets do some tests!
Show curent snapshot list
# snapper list
Type | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+------+------+---------+-------------+---------
single | 0 | | | root | | current |
Lets create a manual snapshot now
# snapper -c root create --description "Initial snapshot df (640004 84%)"
# snapper list
Type | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+---------------------------------+------+---------+-----------------------------------+---------
single | 0 | | | root | | current |
single | 1 | | Wed 12 Feb 2014 03:54:09 PM EST | root | | Initial snapshot df (640004 84%) |
For testinf, we are not going to install a package via apt-get since I do not know what repositories you have, so we will just use apt-get update as an example
snp apt-get update
> New pre snapshot with number 2.
> Running command "apt-get update".
Hit http://update.nzbdrone.com master Release.gpg
Hit http://update.nzbdrone.com master Release
Get:1 http://security.debian.org wheezy/updates Release.gpg [836 B]
Get:2 http://apt.readynas.com 6.1.6 Release.gpg [490 B]
...
Fetched 1,218 kB in 27s (44.2 kB/s)
Reading package lists...
> New post snapshot with number 3.
Now lets check out our snapshots again
# snapper list
Type | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+---------------------------------+------+---------+-----------------------------------+---------
single | 0 | | | root | | current |
single | 1 | | Wed 12 Feb 2014 03:54:09 PM EST | root | | Initial snapshot df (640004 84%) |
pre | 2 | | Wed 12 Feb 2014 03:55:22 PM EST | root | number | apt-get update |
post | 3 | 2 | Wed 12 Feb 2014 03:56:06 PM EST | root | number | |
Lets see what was modified.
# snapper status 2..3
c.... /var/cache/apt/pkgcache.bin
c.... /var/cache/apt/srcpkgcache.bin
c.... /var/lib/apt/lists/apt.readynas.com_packages_readynasos_dists_6.1.6_Release
c.... /var/lib/apt/lists/apt.readynas.com_packages_readynasos_dists_6.1.6_Release.gpg
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_Release
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_Release.gpg
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_main_binary-amd64_Packages
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_main_binary-amd64_Packages.IndexDiff
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_main_source_Sources
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_experimental_main_source_Sources.IndexDiff
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_Release
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_Release.gpg
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_contrib_binary-amd64_Packages
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_contrib_binary-amd64_Packages.IndexDiff
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_main_binary-amd64_Packages
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_main_binary-amd64_Packages.IndexDiff
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_main_source_Sources
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_unstable_main_source_Sources.IndexDiff
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_wheezy-backports_Release
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_wheezy-backports_Release.gpg
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_wheezy-backports_main_binary-amd64_Packages
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_wheezy-backports_main_binary-amd64_Packages.IndexDiff
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_wheezy-backports_main_source_Sources
c.... /var/lib/apt/lists/ftp.debian.org_debian_dists_wheezy-backports_main_source_Sources.IndexDiff
c.... /var/lib/apt/lists/security.debian.org_dists_wheezy_updates_Release
c.... /var/lib/apt/lists/security.debian.org_dists_wheezy_updates_Release.gpg
c.... /var/lib/apt/lists/security.debian.org_dists_wheezy_updates_main_binary-amd64_Packages
c.... /var/lib/apt/lists/security.debian.org_dists_wheezy_updates_main_source_Sources
c.... /var/log/frontview/ssl_access.log
c.... /var/log/journal/aece538b27774406bde00af1df14d369/system.journal
c.... /var/log/snapper.log
c.... /var/log/snp/snp_2014-02-12-155520.log
c.... /var/readynasd/db.sq3
Lets remove the update. Snapper does not tell the kernel about the change, so you must either do so yourself or reboot if required.
# snapper undochange 2..3
create:0 modify:33 delete:0
REMEMBER, lets not keep any of these snapshots around for any length of time since we do not want to fill up the / root partition since that would be really bad!
So lets now delete our snapshots we used for testing
# snapper delete 3
# snapper delete 2
# snapper delete 1
# snapper list
Type | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+------+------+---------+-------------+---------
single | 0 | | | root | | current |
Related Content
NETGEAR Academy
Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology!
Join Us!