From d864de71951506bb245af96cf5f28751f8a3c1a2 Mon Sep 17 00:00:00 2001 From: Justin Timperio Date: Fri, 11 Sep 2020 20:24:03 -0400 Subject: [PATCH] Fixes: - Bumped PAF to Fix Logging Function - Fixed Config File Detection - New Session Locking System Using fcntl Other: - New Users Docs - General Doc Patches --- README.md | 2 ++ USER_GUIDE.md | 12 ++++++++++++ core/pacback.py | 2 +- core/paf | 2 +- core/session.py | 28 +++++++++++++++------------- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fd04531..0d0aee3 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ Pacback offers several core commands that streamline the process of creating and *Example: `pacback -v`* ### Utilities +* - -cache, --cache_size | Calculate reported and actual cache sizes.\ +*Example: `pacback -cl`* * -cl, --clean | Clean old and orphaned pacakages along with old restore points.\ *Example: `pacback -cl`* * -rm, --remove | Removes the selected restore point.\ diff --git a/USER_GUIDE.md b/USER_GUIDE.md index cface9f..085a11e 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -3,6 +3,7 @@ **Table of Contents:** - [Get Snapshot and Restore Point Info](https://github.com/JustinTimperio/pacback/blob/master/USER_GUIDE.md#getting-snapshot-and-restore-point-info) - [Using Rolling System Snapshots](https://github.com/JustinTimperio/pacback/blob/master/USER_GUIDE.md#rolling-system-snapshots) +- [Creating Permanent Restore Points](https://github.com/JustinTimperio/pacback/blob/master/USER_GUIDE.md#creating-permanent-restore-points) - [Rollback a List of Packages](https://github.com/JustinTimperio/pacback/blob/master/USER_GUIDE.md#rollback-a-list-of-packages) - [Rolling Back to an Archive Date](https://github.com/JustinTimperio/pacback/blob/master/USER_GUIDE.md#rolling-back-to-an-archive-date) - [Backup Version Sensitive Application Data](https://github.com/JustinTimperio/pacback/blob/master/USER_GUIDE.md#backup-version-sensitive-application-data) @@ -31,6 +32,17 @@ One of the problems with rolling releases is you never know when a problem might ![Pacback Snapshot](https://i.imgur.com/GE61yqe.gif) +## Creating Permanent Restore Points + +Remember that one time all your packages were working perfectly? (God that was great.) Have a production system running perfectly that needs to be updated but you don't want to backup the whole disk? With pacback restore points, you don't have to lose that version state. Restore points are user-defined version states that describe a set of packages and even configuration files on your system that you don't want to lose track of. Unlike many backup utilities pacback doesn't need backup the whole disk. Instead, it hardlinks packages with inodes without duplicating the files so that pacback can maintain the smallest possible profile on your system. + +To create a restore point, then get information about it: + +1. `pacback -nc -f -c 1 -l 'Production'` +2. `pacback -i rp1` + +![Restore Points](https://i.imgur.com/5f5d5HI.gif) + ## Rollback a List of Packages Most issues introduced by an upgrade stem from a single package or a set of related packages. Pacback allows you to selectively rollback a list of packages using `pacback -pkg`. Packback searches your file system looking for all versions associated with each package name. When searching, Pacback attempts to avoid matching generic names used by multiple packages (I.E. *xorg* in *xorg*-server, *xorg*-docs, *xorg*-xauth). If no packages are found, the search parameters can be widened but it will likely show inaccurate results. diff --git a/core/pacback.py b/core/pacback.py index 1b0fbed..6c94467 100755 --- a/core/pacback.py +++ b/core/pacback.py @@ -65,7 +65,7 @@ parser.add_argument("-ls", "--list", action='store_true', help="List information about all existing restore points and snapshots.") parser.add_argument("-cache", "--cache_size", action='store_true', - help="Calculate a timeline of changes between snapshots.") + help="Calculate reported and actual cache sizes.") args = parser.parse_args() config = session.load_config() diff --git a/core/paf b/core/paf index 4f25050..412fd69 160000 --- a/core/paf +++ b/core/paf @@ -1 +1 @@ -Subproject commit 4f250502fd7900d1929d2c15526da32e474fa1d5 +Subproject commit 412fd698d24d68ad4c039e04a6fb9a79fba8f23d diff --git a/core/session.py b/core/session.py index 68d38fd..013068d 100644 --- a/core/session.py +++ b/core/session.py @@ -1,6 +1,7 @@ #! /usr/bin/env python3 import os import sys +import fcntl import datetime as dt # Local Modules @@ -20,13 +21,15 @@ def lock(config): if paf.am_i_root() is False: sys.exit('Critical Error: This Command Must Be Run As Root!') - if os.path.exists(config['slock']): - sys.exit('Critical Error! Pacback Already Has An Active Session Running.') + try: + lock = os.open(config['slock'], os.O_CREAT) + fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) + paf.start_log(fname, config['log']) + paf.write_to_log(fname, 'Passed Root Check', config['log']) + paf.write_to_log(fname, 'Started Active Session', config['log']) - paf.start_log(fname, config['log']) - paf.write_to_log(fname, 'Passed Root Check', config['log']) - os.system('touch ' + config['slock']) - paf.write_to_log(fname, 'Started Active Session', config['log']) + except (IOError, OSError): + sys.exit('Critical Error! Pacback Already Has An Active Session Running.') def unlock(config): @@ -35,7 +38,6 @@ def unlock(config): This releases the lock that was created by session.lock() ''' fname = 'session.unlock()' - paf.rm_file(config['slock'], sudo=False) paf.write_to_log(fname, 'Ended Active Session', config['log']) paf.end_log(fname, config['log'], config['log_length']) @@ -111,7 +113,7 @@ def hlock_check(config): paf.write_to_log(fname, 'Passed Cooldown Check', config['log']) else: abort(fname, 'A Hook Lock Was Created ' + str(sec_dif) + ' Ago!', - 'Aborting: The Last Snapshot Was Created Less Than ' + str(config['hook_cooldown']) + ' Seconds Ago!', config) + 'Aborting: A Snapshot Was Created Less Than ' + str(config['hook_cooldown']) + ' Seconds Ago!', config) else: paf.write_to_log(fname, 'Passed Check, No Previous Lock Found', config['log']) @@ -127,11 +129,11 @@ def load_config(): mandatory = ['hook_cooldown', 'max_ss', 'reboot'] optional = ['old_rp', 'keep_versions', 'reboot_offset', 'log_length', 'basepath', 'rp_paths', 'ss_paths'] default = { - 'version': '2.0.1', - 'paf': '4f25050', + 'version': '2.0.2', + 'paf': '412fd69', 'log': '/var/log/pacback.log', - 'slock': '/tmp/pacback_session.lck', - 'hlock': '/tmp/pacback_hook.lck', + 'slock': '/var/lib/pacback/pacback_session.lck', + 'hlock': '/var/lib/pacback/pacback_hook.lck', 'basepath': '/var/lib/pacback', 'rp_paths': '/var/lib/pacback/restore-points', 'ss_paths': '/var/lib/pacback/snapshots', @@ -173,5 +175,5 @@ def setup(config): paf.mk_dir(config['ss_paths'], sudo=False) paf.write_to_log(fname, 'Created Snapshot Folder at ' + config['ss_paths'], config['log']) - if os.path.exists('/etc/pacback/config') is False: + if os.path.exists('/etc/pacback.conf') is False: paf.write_to_log(fname, 'User Config File Is Missing!', config['log'])