diff --git a/DC-snapper-undo-changes b/DC-snapper-undo-changes new file mode 100644 index 000000000..e0c351df5 --- /dev/null +++ b/DC-snapper-undo-changes @@ -0,0 +1,17 @@ +# This file originates from the project https://github.com/openSUSE/doc-kit +# This file can be edited downstream. + +MAIN="snapper-undo-changes.asm.xml" +ROOTID="snapper-undo-changes" +SRC_DIR="articles" +IMG_SRC_DIR="images" + +PROFOS="generic" +#PROFCONDITION="suse-product" +#PROFCONDITION="suse-product;beta" +#PROFCONDITION="community-project" + +STYLEROOT="/usr/share/xml/docbook/stylesheet/suse2022-ns" +FALLBACK_STYLEROOT="/usr/share/xml/docbook/stylesheet/suse2022-ns" +DOCBOOK5_RNG_URI="urn:x-suse:rng:v2:geekodoc-flat" +XSLTPARAM="--param generate.json-ld=1 " diff --git a/articles/snapper-undo-changes.asm.xml b/articles/snapper-undo-changes.asm.xml new file mode 100644 index 000000000..308a7b253 --- /dev/null +++ b/articles/snapper-undo-changes.asm.xml @@ -0,0 +1,169 @@ + + + + + %entities; +]> + + + + + + + + + + For more information + + + Comparing rollback and undoing changes + + + + + + Introduction + + + Undoing &yast; and &zypper; changes + + + Restoring files with &snapper; + + + + + + Legal Notice + + + GNU Free Documentation License + + + + + + Using &snapper; to undo changes + + 2024-01-04 + + + This topic merges and updates the content about using Snapper to + undo changes and restore files from the Snapper chapter 10.2 in + the &productname; Admin Guide. + + + + + + + + &x86-64; + &power; + &zseries; + &aarch64; + + + &alp; + + Using &snapper; to undo changes + How to use &snapper; to undo &yast; and &zypper; changes + and restore files; comparison between undoing changes and rollback + Undo &yast; and &zypper; changes with &snapper; + + Backup & Recovery + Administration + + Products & Solutions + + + https://bugzilla.suse.com/enter_bug.cgi + Smart Docs + Documentation + daria.vladykina@suse.com + + yes + + + + + WHAT? + + + This article describes how to use &snapper; in its default configuration + to undo changes performed with &yast; and &zypper; and to restore files. + + + + + WHY? + + + You aim to learn about &snapper;'s most commonly used functionality: undoing changes. + + + + + EFFORT + + + It takes up to 15 minutes to read about reverting changes and restoring files + with &snapper;. + + + + + REQUIREMENTS + + + + + &rootuser; or &sudo; privileges + + + + + Snapper needs to be installed. It is available on &productname; by default. + + + + + The root partition (/) size of at least 16 GB. + + + + + + + + This article is the second installment of the series of articles + about &snapper;. In the first article, we covered the core principles + of &snapper;—see + The Basic Concepts of Snapper. + Subsequent articles will cover &snapper;'s other use cases such as rolling + back the system, manually creating and managing snapshots, and automatic + snapshot cleanup. + + + + + + + + + + + + diff --git a/concepts/snapper-undo-changes-intro.xml b/concepts/snapper-undo-changes-intro.xml new file mode 100644 index 000000000..4d5f2af35 --- /dev/null +++ b/concepts/snapper-undo-changes-intro.xml @@ -0,0 +1,96 @@ + + + %entities; + + + + +]> + + + + + + + Default configuration + + + + &snapper; on &productname; is preconfigured to serve as a tool that lets you + undo changes made by zypper and &yast;. It does this + by creating a pair of snapshots before and after each run of zypper + and &yast;. + + + + Taking snapshot pairs upon installing packages with &yast; or &zypper; is + handled by snapper-zypp-plugin. An XML + configuration file, /etc/snapper/zypp-plugin.conf, defines + when to make snapshots. By default, the file looks like the following: + + +<?xml version="1.0" encoding="utf-8"?> +<snapper-zypp-plugin-conf> +<solvables> +<solvable match="w" important="true">kernel-*</solvable> +<solvable match="w" important="true">dracut</solvable> +<solvable match="w" important="true">glibc</solvable> +<solvable match="w" important="true">systemd*</solvable> +<solvable match="w" important="true">udev</solvable> +<solvable match="w">*</solvable> +</solvables> +</snapper-zypp-plugin-conf> + + + + The match attribute defines whether the pattern is a Unix shell-style + wild card (w) or a Python regular expression + (re). For more information about regular expressions in Python, + refer to Regular expression operations. + + + + + If the pattern matches and the corresponding package is marked as + important (for example, kernel packages), the snapshot will also be + marked as important. + + + + + Pattern to match a package name. Based on the setting of the + match attribute, special characters are + interpreted as shell wild cards or regular expressions. This pattern + matches all package names, starting with kernel-. + + + + + This line unconditionally matches all packages. + + + + + With this configuration snapshot, pairs are made whenever a package is + installed (see ). When the kernel, dracut, glibc, systemd, or udev packages + marked as important are installed, the snapshot pair will also be marked + as important. All rules are evaluated. + + By default, automatic snapshots as described above are configured for the + root partition and its subvolumes. To make snapshots available for other + partitions such as /home, for example, you can create + custom configurations. + + &snapper; also lets you restore system files that have been accidentally + deleted or modified. Timeline snapshots for the root partition need to be + enabled for this purpose. + + diff --git a/glues/snapper-undo-changes-compare-undo-and-rollback.xml b/glues/snapper-undo-changes-compare-undo-and-rollback.xml new file mode 100644 index 000000000..754584c75 --- /dev/null +++ b/glues/snapper-undo-changes-compare-undo-and-rollback.xml @@ -0,0 +1,63 @@ + + + %entities; + +]> + + + Undoing changes compared to rollback with &snapper; + + + When working with snapshots to restore data, it is important to know that + there are two fundamentally different scenarios &snapper; can handle: + undoing changes and rollback. The key difference between them is the level + of granularity and the scope of the operation. + + + + +
+ Undoing changes with &snapper; + To undo changes made between two snapshots, the undochange + command is used. This command allows you to reverse the effects of a specific + action within a transaction without impacting subsequent changes. For example, + if you have a configuration file that was modified in a certain snapshot and + you want to revert that change, use the undochange + command to do so. + + When undoing changes, two snapshots are + being compared and the changes between these two snapshots are made + undone. Using this method, you can explicitly select the files + that need to be restored. + +
+ +
+ Rollback with &snapper; + In comparison with undoing changes, a rollback is a more comprehensive + operation that reverts the entire file system to a previous snapshot, including + configurations and system files. This is useful when you want to revert + multiple transactions and return the system to a previous state, erasing + all changes made after a specific transaction. + + When doing rollbacks, + the system is reset to the state at which the snapshot was taken. + + + When undoing changes, it is also possible to compare a snapshot against the + current system. When restoring all files from such a + comparison, this will have the same result as doing a rollback. + +
+
diff --git a/glues/snapper-undo-changes-more-info.xml b/glues/snapper-undo-changes-more-info.xml new file mode 100644 index 000000000..04ab983df --- /dev/null +++ b/glues/snapper-undo-changes-more-info.xml @@ -0,0 +1,50 @@ + + + %entities; + +]> + + + For more information + + + + + + + + + For more detailed information on how to do system rollback by + booting from snapshots, see + + + + + + For more information on creating additional &snapper; configurations, see + + + + + + For more information about backup snapshots, see + + + + + + For more information about creating custom configurations, see + + + + + diff --git a/images/snapper-yast-changes.png b/images/snapper-yast-changes.png new file mode 100644 index 000000000..879c90573 Binary files /dev/null and b/images/snapper-yast-changes.png differ diff --git a/images/snapper-yast-diff.png b/images/snapper-yast-diff.png new file mode 100644 index 000000000..b8b156f9d Binary files /dev/null and b/images/snapper-yast-diff.png differ diff --git a/images/snapper-yast-list.png b/images/snapper-yast-list.png new file mode 100644 index 000000000..cfa4cb7e7 Binary files /dev/null and b/images/snapper-yast-list.png differ diff --git a/images/snapper-yast-restore.png b/images/snapper-yast-restore.png new file mode 100644 index 000000000..087a04e17 Binary files /dev/null and b/images/snapper-yast-restore.png differ diff --git a/tasks/snapper-undo-changes-restore-files.xml b/tasks/snapper-undo-changes-restore-files.xml new file mode 100644 index 000000000..b99a7a2f2 --- /dev/null +++ b/tasks/snapper-undo-changes-restore-files.xml @@ -0,0 +1,165 @@ + + + %entities; + + + +]> + + + + + + + Using &snapper; to restore files + + + + &snapper; provides the functionality to restore system files that may + have been accidentally deleted or modified, or to restore previous versions + of files. + + + To use the restore feature, timeline snapshots for the root partition + must be activated. They provide a historical record of the state of the file + system over time. This allows you to select a specific snapshot to restore + from, rather than having to restore the entire file system. + You can also find out which modifications were made at a certain point + in time. To do so, use &snapper;'s diff feature. + + Being able to restore files is especially interesting for data that may + reside on subvolumes or partitions for which snapshots are not taken by + default. For example, to restore files from home directories, you need to + create a separate &snapper; configuration for /home + doing automatic timeline snapshots. + + + Restoring files compared to rollback + + Snapshots taken from the root file system (defined by &snapper;'s root + configuration) can be used to do a system rollback. The recommended way + to do such a rollback is to boot from the snapshot and then perform the + rollback. + + + Performing a rollback would also be possible by restoring all files from a + root file system snapshot as described below. However, this is not + recommended. You may restore single files, for example, a configuration + file from the /etc directory, but not the + complete list of files from the snapshot. + + + This restriction only affects snapshots taken from the root file system. + + + + Restoring files using the &yast; <guimenu>Snapper</guimenu> module + To restore files with the &snapper; module in &yast;, follow these steps: + + + Open the Miscellaneous section in &yast; or enter the command + yast2 snapper to open it, and start the Filesystem + Snapshots module. + + + + + Select the Current Configuration from which to choose + a snapshot. + + + + + Select a timeline snapshot from which to restore a file and click + Show Changes. Timeline snapshots are of the type + Single with a description value of + timeline. + + + + + Select a file from the text box by clicking the file name. The difference + between the snapshot version and the current system is shown. Activate + the check box to select the file for restore. Do so for all files you + want to restore. + + + + + Click Restore Selected and confirm the action by + clicking Yes. + + + + + Restoring files using the <command>snapper</command> command + To restore files with the snapper command, perform + the following steps: + + + Get a list of timeline snapshots for a specific configuration by running + the following command: + + &prompt.sudo;snapper -c CONFIG list -t single | grep timeline + + CONFIG needs to be replaced by an existing + &snapper; configuration. Use snapper list-configs to + display a list. + + + + + Get a list of changed files for a given snapshot by running the following + command: + + &prompt.sudo;snapper -c CONFIG status SNAPSHOT_ID..0 + + Replace SNAPSHOT_ID with the ID for the snapshot + from which you want to restore the files. + + + + + Optionally list the differences between the current file version and the + one from the snapshot by running + + &prompt.sudo;snapper -c CONFIG diff SNAPSHOT_ID..0 FILE NAME + + If you do not specify <FILE NAME>, the + difference for all files is shown. + + + + + To restore one or more files, run + + &prompt.sudo;snapper -c CONFIG -v undochange SNAPSHOT_ID..0 FILENAME1 FILENAME2 + + If you do not specify file names, all changed files will be restored. + + + + + + Data consistency + + There is no mechanism to ensure data consistency when creating a snapshot. + Whenever a file (for example, a database) is written at the same time as the + snapshot is being created, it will result in a corrupted or partly written + file. Restoring such a file will cause problems. Furthermore, certain system + files, such as /etc/mtab, must never be restored. + Therefore, we strongly recommend to always closely + review the list of changed files and their diffs. Only restore files that + really belong to the action you want to revert. + + + + diff --git a/tasks/snapper-undo-changes-yast-zypper.xml b/tasks/snapper-undo-changes-yast-zypper.xml new file mode 100644 index 000000000..6e94fe62c --- /dev/null +++ b/tasks/snapper-undo-changes-yast-zypper.xml @@ -0,0 +1,274 @@ + + + %entities; + + + + +]> + + + + + + + Undoing &yast; and &zypper; changes + + + + When the root partition is set up with Btrfs during the + installation, &snapper; is installed automatically and is preconfigured for + doing rollbacks of &yast; and &zypper; changes. Every time you start + a &yast; module or a &zypper; transaction, two snapshots are created: a + pre snapshot capturing the state of the file system before + the start of the module, and a post snapshot after the module + has been finished. + You can undo the changes made by &yast; and &zypper; by using the &snapper; + module in &yast; or the snapper command-line tool. Both allow + restoring files from pre snapshots. When comparing two + snapshots, the tools show which files were changed. You can also + display the differences between two versions of a file (diff). + + + +
+ Undoing changes using the &snapper; module in &yast; + To undo changes with the &snapper; module in &yast;, follow these steps: + + + Undoing changes using the &yast; <guimenu>Snapper</guimenu> module + + + Open the Miscellaneous section in &yast; or enter the command + yast2 snapper to open it, and start the Filesystem + Snapshots module. + + + + + Make sure Current Configuration is set to + root. This is always the case unless you have manually + added own &snapper; configurations. + + + + + Choose a pair of pre and post snapshots + from the list. Both &yast; and &zypper; snapshot pairs are of the type + Pre & Post. &yast; snapshots are labeled as + zypp(y2base) in the Description column; + &zypper; snapshots are labeled zypp(zypper). + + + + + + + + + + + Start the &snapper; module in &yast; and listing snapshots + + + + + + + Click Show Changes to open the list of files that + differ between the two snapshots. + + + + + + + + + + + Show list of changes in two snapshots in &yast; + + + + + + + Review the list of files. To display a diff between the + pre and post version of a file, + select it from the list. + + + + + + + + + + Display diff of pre and post file versions in &yast; + + + + + + + To restore one or more files, select the relevant files or directories by + activating the respective check box. Click Restore + Selected and confirm the action by clicking + Yes. + + + + + + + + + + + Restore selected files in &yast; + + + + + To restore a single file, activate its diff view by clicking its name. + Click Restore From First and confirm your choice with + Yes. + + + +
+ +
+ Undoing changes using the <command>snapper</command> command + To undo changes with the snapper command, follow these steps: + + + Undoing changes using the <command>snapper</command> command + + + Get a list of &yast; and &zypper; snapshots by running snapper + list -t pre-post. &yast; snapshots are labeled + as yast MODULE_NAME in the + Description column; &zypper; snapshots are labeled + zypp(zypper). + +&prompt.sudo;snapper list -t pre-post +Pre # | Post # | Pre Date | Post Date | Description +------+--------+-------------------------------+-------------------------------+-------------- +311 | 312 | Tue 06 May 2018 14:05:46 CEST | Tue 06 May 2018 14:05:52 CEST | zypp(y2base) +340 | 341 | Wed 07 May 2018 16:15:10 CEST | Wed 07 May 2018 16:15:16 CEST | zypp(zypper) +342 | 343 | Wed 07 May 2018 16:20:38 CEST | Wed 07 May 2018 16:20:42 CEST | zypp(y2base) +344 | 345 | Wed 07 May 2018 16:21:23 CEST | Wed 07 May 2018 16:21:24 CEST | zypp(zypper) +346 | 347 | Wed 07 May 2018 16:41:06 CEST | Wed 07 May 2018 16:41:10 CEST | zypp(y2base) +348 | 349 | Wed 07 May 2018 16:44:50 CEST | Wed 07 May 2018 16:44:53 CEST | zypp(y2base) +350 | 351 | Wed 07 May 2018 16:46:27 CEST | Wed 07 May 2018 16:46:38 CEST | zypp(y2base) + + + + Get a list of changed files for a snapshot pair with snapper + status + PRE..POST. Files + with content changes are marked with c, files that + have been added are marked with + and deleted files + are marked with -. + +&prompt.sudo;snapper status 350..351 ++..... /usr/share/doc/packages/mikachan-fonts ++..... /usr/share/doc/packages/mikachan-fonts/COPYING ++..... /usr/share/doc/packages/mikachan-fonts/dl.html +c..... /usr/share/fonts/truetype/fonts.dir +c..... /usr/share/fonts/truetype/fonts.scale ++..... /usr/share/fonts/truetype/みかちゃん-p.ttf ++..... /usr/share/fonts/truetype/みかちゃん-pb.ttf ++..... /usr/share/fonts/truetype/みかちゃん-ps.ttf ++..... /usr/share/fonts/truetype/みかちゃん.ttf +c..... /var/cache/fontconfig/7ef2298fde41cc6eeb7af42e48b7d293-x86_64.cache-4 +c..... /var/lib/rpm/Basenames +c..... /var/lib/rpm/Dirnames +c..... /var/lib/rpm/Group +c..... /var/lib/rpm/Installtid +c..... /var/lib/rpm/Name +c..... /var/lib/rpm/Packages +c..... /var/lib/rpm/Providename +c..... /var/lib/rpm/Requirename +c..... /var/lib/rpm/Sha1header +c..... /var/lib/rpm/Sigmd5 + + + + To display the diff for a certain file, run snapper + diff. It follows this syntax: + + snapper diff PRE..POST [FILENAME] + + + If you do not specify a + FILENAME, a diff for all files will be + displayed. + +&prompt.sudo;snapper diff 350..351 /usr/share/fonts/truetype/fonts.scale +--- /.snapshots/350/snapshot/usr/share/fonts/truetype/fonts.scale 2014-04-23 15:58:57.000000000 +0200 ++++ /.snapshots/351/snapshot/usr/share/fonts/truetype/fonts.scale 2014-05-07 16:46:31.000000000 +0200 +@@ -1,4 +1,4 @@ +-1174 ++1486 + ds=y:ai=0.2:luximr.ttf -b&h-luxi mono-bold-i-normal--0-0-0-0-c-0-iso10646-1 + ds=y:ai=0.2:luximr.ttf -b&h-luxi mono-bold-i-normal--0-0-0-0-c-0-iso8859-1 +[...] + + + + To restore one or more files, run snapper -v undochange + PRE..POST + FILENAME. If you do not specify a + FILENAME, all the changed files will be restored. + +&prompt.sudo;snapper -v undochange 350..351 +create:0 modify:13 delete:7 +undoing change... +deleting /usr/share/doc/packages/mikachan-fonts +deleting /usr/share/doc/packages/mikachan-fonts/COPYING +deleting /usr/share/doc/packages/mikachan-fonts/dl.html +deleting /usr/share/fonts/truetype/みかちゃん-p.ttf +deleting /usr/share/fonts/truetype/みかちゃん-pb.ttf +deleting /usr/share/fonts/truetype/みかちゃん-ps.ttf +deleting /usr/share/fonts/truetype/みかちゃん.ttf +modifying /usr/share/fonts/truetype/fonts.dir +modifying /usr/share/fonts/truetype/fonts.scale +modifying /var/cache/fontconfig/7ef2298fde41cc6eeb7af42e48b7d293-x86_64.cache-4 +modifying /var/lib/rpm/Basenames +modifying /var/lib/rpm/Dirnames +modifying /var/lib/rpm/Group +modifying /var/lib/rpm/Installtid +modifying /var/lib/rpm/Name +modifying /var/lib/rpm/Packages +modifying /var/lib/rpm/Providename +modifying /var/lib/rpm/Requirename +modifying /var/lib/rpm/Sha1header +modifying /var/lib/rpm/Sigmd5 +undoing change done + + + + Reverting user additions + + We do not recommend reverting user additions via undoing changes with &snapper;. + Since certain directories are excluded from snapshots, files belonging to + these users will remain in the file system. If a new user is created that + has the same user ID as a deleted user, this new user will inherit the + files. Therefore, it is strongly recommended to use the &yast; + User and Group Management tool to remove users. + + +
+