You are not logged in.

#1 2017-05-19 10:53:02

jackpot
Member
From: Riyadh, Saudi Arabia
Registered: 2014-08-18
Posts: 86

[Solved] Problem in automating pacman database backups using Systemd

Hi,

I am trying to setup automated monthly pacman database backups to my Dropbox folder using systemd-timers as user (not root) and facing two problems, appreciate any help:

Service and timer files used are:

Path: /home/me/.config/systemd/user/pacbac.service

[Unit]
 Description=Automatic backup of pacman database

[Service]
 Type=simple
 ExecStart=/usr/bin/tar -cjf /home/me/Dropbox/Arch/pacman_backups/$(date +%d%m%y).tar.bz2 /var/lib/pacman/local
 TimeoutStopSec=180
 KillMode=process
 KillSignal=SIGINT

[Install]
 WantedBy=multi-user.target
 Alias=pacbac.service

Path: /home/me/.config/systemd/user/pacbac.timer

[Unit]
Description=Timing of executing automatic backups of pacman database

[Timer]
OnCalendar=monthly
Persistent=true     
Unit=pacbac.service
 
[Install]
WantedBy=timers.target

Two problems are as follows:

1. Intended file name:

tar -cjf '/home/me/Dropbox/Arch/pacman_backups/'$(date +%d%m%y).tar.bz2 /var/lib/pacman/local

If run in terminal give intended name to tarball, for example, as "190517.tar.bz2" in right path but the same argument in pacbac.service is resulting in broken name like "$ (date". Argument used in pacbac.service file is as follows:

 ExecStart=/usr/bin/tar -cjf '/home/me/Dropbox/Arch/pacman_backups/'$(date +%d%m%y).tar.bz2 /var/lib/pacman/local

2.  Status of service:

When I start service using systemctl --user start pacbac.service, systemctl --user status pacbac.service returns:

● pacbac.service - Automatic backup of pacman database
   Loaded: loaded (/home/me/.config/systemd/user/pacbac.service; disabled; vendor preset: enabled)
==>   Active: failed (Result: exit-code) since Fri 2017-05-19 13:30:00 +03; 25min ago
  Process: 11815 ExecStart=/usr/bin/tar -cjf /home/me/Dropbox/Arch/pacman_backups/$(date +%d%m%y).tar.bz2 /var/lib/pacman/local (code=exited, status=2)
 Main PID: 11815 (code=exited, status=2)

May 19 13:29:56 my systemd[704]: Started Automatic backup of pacman database.
==> May 19 13:29:56 my tar[11815]: /usr/bin/tar: +%d1bfa269d5c9d46c5912fb4892974b9d3%y).tar.bz2: Cannot stat: No such file or directory
May 19 13:29:56 my tar[11815]: /usr/bin/tar: Removing leading `/' from member names
May 19 13:30:00 my systemd[704]: pacbac.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
May 19 13:30:00 my systemd[704]: pacbac.service: Unit entered failed state.
May 19 13:30:00 my systemd[704]: pacbac.service: Failed with result 'exit-code'.
Warning: pacbac.service changed on disk. Run 'systemctl --user daemon-reload' to reload units.

Seeking solution for:

#1 How to fix naming of tarball?

#2 While serving is doing it's job (I can see tarball with unintended name) then why two lines in above code marked as "==>"?

Thanks.

Last edited by jackpot (2017-05-19 12:36:22)


KDE is all good bloated, try to trim away from K*.apps... whatever it leaves behind equals "Kuck yourself!"
nVidia.... fsck sdy0

Offline

#2 2017-05-19 11:01:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: [Solved] Problem in automating pacman database backups using Systemd

The problem for both are the same.  What you set in ExecStart is passed to an exec system call, not to a shell interpreter.  If you need to run a shell, you need to exec /bin/sh or /bin/bash and pass the shell commands as parameters to that.  Alternatively, put the commands in a script, and just launch that script from the service file.

Systemd does expand the %m to your machine id (see `man systemd.unit`) but the %d and %y don't mean anything.  So the command it exec's is as follows:

arg[0] = /usr/bin/tar
arg[1] = -cjf
arg[2] = /home/me/Dropbox/Arch/pacman_backups/$(date
arg[3] = +%d1bfa269d5c9d46c5912fb4892974b9d3%y).tar.bz2
arg[4] = /var/lib/pacman/local

With this exec, tar tries to create a tarball without an extension, but it is told to look for a file named as that ugly string in arg[3] to include in the tarball.  No such file exists.

On another note, I'm also not sure why you'd want to backup the local database.  You know this doesn't include the package files right?  I don't see a need to back up package files given that we have the arch linux archive already, but keeping the cached pkg.tar.xz files around at least serves a purpose - I really can't imagine how a backup of the local database would ever be useful.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2017-05-19 11:28:08

jackpot
Member
From: Riyadh, Saudi Arabia
Registered: 2014-08-18
Posts: 86

Re: [Solved] Problem in automating pacman database backups using Systemd

Thanks for quick reply.

My years old setup recently broke after RAM upgrade. PC was having hiccups as random restarts, one of which, happened during pacman -Syu, /var got corrupted and I had to do manual fsck to repair orphaned inodes. Eventually, pacman local database got deleted which required installation of 1) base system and then 2) the software I needed.

I thought local backups would be helpful to reinstall all software if anything goes beyond repair. However, your comments suggest that the idea is not worthwhile. Should I abandon?


KDE is all good bloated, try to trim away from K*.apps... whatever it leaves behind equals "Kuck yourself!"
nVidia.... fsck sdy0

Offline

#4 2017-05-19 11:33:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: [Solved] Problem in automating pacman database backups using Systemd

I suppose a backup of the /var/lib/pacman/local would have helped in the specific situation you describe where there was a problem in /var/lib/pacman/local.  But there is nothing special about that path: if any file gets corrupted a backup would help.  So backing up everything is always a good idea.

Again though, there's nothing particularly special about that path.  The content of that path would not help you to reinstall packages except to the degree it provides a list of which packages are/were installed (a backup of /var/cache/pacman/pkgs would, but this is what is available on the archlinux archive).  But if you just want a list of installed packages, just make a list of installed packages (pacman -Qeq > list).


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB