0

I want to backup the pacman sync databases after an execution of pacman -Sy, creating "restore points" which pacman -Suu can use to reverse a failed system upgrade. Further background can be found here.

I want to manually lock the pacman databases via/var/lib/pacman/db.lck to ensure that the databases are not changed while being saved / restored.

How to I atomically check/create /var/lib/pacman/db.lck?

4
  • 1
    You don't. Let pacman do its job.
    – jasonwryan
    Commented Feb 17, 2017 at 6:01
  • @jasonwryan pacman doesn't do the job of saving and restoring versions of databases, so I don't follow you.
    – Tom Hale
    Commented Feb 17, 2017 at 6:35
  • You don't restore databases; you restore packages and let pacman update the database accordingly.
    – jasonwryan
    Commented Feb 17, 2017 at 6:37
  • I've updated the question to explain why I do want to restore databases.
    – Tom Hale
    Commented Feb 17, 2017 at 7:22

1 Answer 1

2

Locking the databases

mkdir is an atomic operation which will avoid concurrency issues.

sudo mkdir /var/lib/pacman/db.lck 2>/dev/null && echo Got lock || echo Locked out

I tested the above while running pacman -Syy in another shell. The output is "Locked out" while pacman is running, and "Got lock" after it completes.

Reciprocally, pacman -Syy will say that it can't lock the database while the directory exists.

Backup

I wrote a paranoia_level=9 bash script which safely saves the sync databases to directories under /var/lib/pacman/backup named by ISO8601 date.

The script also saves non-dependency packages lists of:

  • all packages
  • sync packages
  • foriegn (eg AUR) packages

Usage of backups

Uset the -b option to specify a different location for the databases, eg:

pacman -Suu -b /var/lib/pacman/backup/2017-02-26T12:55:26+07:00
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .