Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate backintime with systemd for scheduling, snapshot control and logs #669

Closed
zimy opened this issue Nov 26, 2016 · 19 comments
Closed
Assignees
Labels
Feature requests a new feature Medium Scheduling cron, anacron etc.

Comments

@zimy
Copy link

zimy commented Nov 26, 2016

It would be nice to have ability to fetch backup logs using say journalctl -u backintime-john -e -f , run backup with systemctl start backintime-john-profilename, enable time-based backup using systemctl enable backintime-john-profilename.timer
So probably creating systemd units at user or system scope for running backup jobs and systemd.timer for running it repeatedly may be useful.

Can you please also recommend how to modify backintime gnome GUI sources to play with such a functionality by myself?

@Germar
Copy link
Member

Germar commented Nov 27, 2016

I've no experience with systemd timers, yet. But I'll have a look.

Gnome GUI is gone. Current master only has one Qt5 GUI. New schedules would need to go into common/config.py defined in dict SCHEDULE_MODES and have their setup in method Config.cronLine. GUI changes would need to be done in qt/settingsdialog.py lines 303-385

@zimy
Copy link
Author

zimy commented Dec 4, 2016

I have created some examples to run on my laptop. My Back In Time configuration have a number of profiles, but basically I use first for testing.
Systemd user process is started with user's first session creation and dies as last session dies, so following tasks will run when you are logged in. To spawn systemd --user at boot user shoud call loginctl enable-linger to be backed up when not logged in.

Two files were created manually at ~/.config/systemd/user.
backintime-job-1.service:

[Unit]
Description=Run backintime job 1

[Service]
ExecStart=/usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime backup
Type=oneshot

and backintime-job-1.timer:

[Unit]
Description=backup of home dir and some configurations

[Timer]
OnCalendar=hourly
Persistent=true

[Install]
WantedBy=default.target

After placing such files I have executed systemctl --user daemon-reload and systemctl --user enable backintime-job-1.timer to make systemd --user seeing them and considering timer activated.

One profit of using such a way is that per-user systemd configuration can be backuped by Back In Time itself without system read privileges!

@aexoxea
Copy link

aexoxea commented Dec 16, 2016

Thank you @zimy for this.

I've also been using systemd to schedule BIT backups recently, using a slightly different approach which I thought I'd share (apologies if no-one wants to see this). Here are my user units:

backintime@.service:

[Unit]
Description=Backup using Back In Time user profile id %I (service unit)
Documentation=man:backintime(1)

[Service]
Type=simple
ExecStart=/usr/bin/backintime --profile-id %I backup

[Install]
DefaultInstance=1
Also=backintime@.timer

backintime@.timer:

[Unit]
Description=Backup using Back In Time user profile id %I (timer unit)
Documentation=man:backintime(1)

[Timer]
OnCalendar=*:00/15

[Install]
DefaultInstance=1
WantedBy=timers.target

Except for the Descriptions, the system units are the same. All unit files are installed under the appropriate subdirectories in /usr/lib/systemd/.

I set these units up to emulate the behaviour listed on the FAQ page under "How does the 'Repeatedly (anacron)' schedule work?", which I've then overridden as needed using drop-ins to set my own schedules and other parameters (as I have disabled BIT's scheduling and just let systemd manage it).

I made these into template units as I have multiple system-level backup profiles, making it easy to instantiate these (i.e. systemctl enable backintime@1.timer backintime@2.timer .. backintime@n.timer). The profile ID seemed like the easiest string to use for my use case.

The service units are listed as "indirect" as they are meant to be triggered by the timer, but can still be started directly (e.g. systemctl start backintime@1.service) and will make a single unscheduled backup if BIT deems this appropriate.


Update 2017-02-19: I saw a social media post recently which pointed out that timer units should be WantedBy=timers.target, and indeed this is recommended in systemd.special(7). I updated my local units on that basis, and felt I should update this comment (since the report is open).

Update 2017-03-20: Updated with workaround for v1.1.14 per #720. This option comes from systemd.exec(5). Fixed; removed.

Update 2017-04-21: For some reason forking type doesn't seem to work reliably anymore with "backup-job" (it looks like the forking doesn't happen -- or else exit immediately -- and then systemd fails unit when its start timeout is hit). As a workaround, I'm using "backup" with the default (simple) type. Not sure if that should be reported here or not.

Separately (and just for anyone interested), systemd.exec(5) contains options that service units can use for CPUSchedulingPolicy=, CPUSchedulingPriority=, IOSchedulingClass=, IOSchedulingPriority= and Nice=.

@Germar
Copy link
Member

Germar commented Dec 16, 2016

Thank you both @zimy and @aexoxea! I'll have a look soon on how I can implement this.

@Elm7
Copy link

Elm7 commented Sep 22, 2017

Hi, just wondering how things are going about this issue. Backintime is very handy compared to all other similar software I know and this systemd option is awaited to ingrate it in the SolusOs repository. (see https://dev.solus-project.com/T729 and https://dev.solus-project.com/T1942 ). Thank a lot for your work anyway.

@laubster
Copy link

Bump... another Solus user expressing interest for backintime supporting systemd timers. (I used & loved backintime on my old system.)

@Germar
Copy link
Member

Germar commented Mar 1, 2018

I hardly find time to provide support for BiT. New features like this are nearly impossible for me at the moment. Sorry

@dataprolet
Copy link

Sorry for reviving this, but it seems that BIT is putting the cronjob back in my crontab, even though I had commented it out to use my systemd-timer instead. Is there an easy way around this? Otherwise the systemd-timer is somewhat pointless, when BIT is also creating a snapshot according to the cronjob.

@emtiu emtiu added Scheduling cron, anacron etc. Feature requests a new feature Discussion decision or consensus needed and removed wishlist labels Sep 12, 2022
@emtiu emtiu changed the title Systemd timers at user or system scope Integrate backintime with systemd for scheduling, snapshot control and logs Sep 12, 2022
@emtiu emtiu added the Low relevant, but not urgent label Sep 12, 2022
@emtiu
Copy link
Member

emtiu commented Sep 12, 2022

@dataprolet wrote:

Sorry for reviving this, but it seems that BIT is putting the cronjob back in my crontab, even though I had commented it out to use my systemd-timer instead. Is there an easy way around this? Otherwise the systemd-timer is somewhat pointless, when BIT is also creating a snapshot according to the cronjob.

If I understand correctly, you can just set the schedule to Disabled in the GUI and use your timer to call the backintime command to take snapshots.

@dataprolet
Copy link

Thank you, that's easier than I though!

@emtiu
Copy link
Member

emtiu commented Sep 12, 2022

From what I see here, logging to the systemd journal would be the only thing that might require changes to backintime. Everything else can be accomplished by writing unit files that contain calls to the backintime command.

The backintime project might ship such unit files, but we'd have to find someone to write, test and maintain(!) them, given that systemd is … shall we say: a moving target.

Keeping this open with the Discussion decision or consensus needed Label.

@xalmat
Copy link

xalmat commented Jun 9, 2023

I don't know about using systemd journals for storing logs, but some distros (Fedora for example) no longer ship or enable cron by default. They prefer scheduling tasks now using systemd.timer. I found this out when trying to schedule automated backups with BiT .

This creates some unneeded new user friction in configuring BiT. It might also become a problem if some distros decide to drop cron altogether.

With that in mind I would like to see BiT at least support scheduling via systemd.timer as a built in option (in the same way that cron is).

@buhtz
Copy link
Member

buhtz commented Jun 9, 2023

Thanks for reporting this. Which version of Fedora was that?

@hannes101
Copy link

Although it is correct that fedora does not ship and enables cron by default, it should be installed together with backintime. Since cronie is a dependency and backintime can't be installed without it.
@xalmat could you perhaps give me a little bit more details on which additional steps are needed? Perhaps there is something we can do about it on the packaging side of backintime.

On the overall development of the distro and on the scheduling system I can't really add a lot of details. Since I just use fedora as a desktop OS I don't make use of a lot of scheduling. However, I have a scheduled task of backintime, which I set up so long ago that I don't remember any particular problems.

@buhtz
Copy link
Member

buhtz commented Jun 18, 2023

If Fedora is without cron, than I assume that scheduling BIT doesn't work there.

@hannes101
Copy link

Whenever backintime is installed, also cron gets installed on fedora. So it should actually work, I think. I would like to get some information, what exactly were the additional steps @xalmat had to do to get it working.

@buhtz
Copy link
Member

buhtz commented Dec 7, 2023

See #610 which is about fcron support and re-designing the related to code to encapsulate the underlying scheduling technic.

@buhtz
Copy link
Member

buhtz commented Jun 4, 2024

Multiple topics here.
Cron on Fedora: There are some distros (most of them Arch-based) that install cron but do not enable it by default. Maybe Fedora behave the same? See #1741 for a feature request to check if cron is running or not.

systemd-timers: I don't see that we do support it in the near feature. Cron run everywhere, systemd don't. It is a matter of resources. But if there is a contributor willing to implement systemd-timer support I am happy to guide you through the contribution process.

About logging: This was a bug that is fixed now. BIT use syslog which goes into journalctl, too. But the identifier was not set appropriate in previous versions. See this FAQ entry about how to read BIT related log entries: https://github.com/bit-team/backintime/blob/dev/FAQ.md#how-to-read-log-entries

Closing this issue after a cool off periode.

@buhtz buhtz self-assigned this Jun 4, 2024
@buhtz buhtz added Close after cooling-off period and removed Discussion decision or consensus needed labels Jun 4, 2024
@buhtz
Copy link
Member

buhtz commented Jun 17, 2024

Closing this ticket based on the comment above. Feel free to reopen
if the problem still exists. Thank you for your efforts. If you have
any further questions, ideas or encounter any other issues, please
don't hesitate to let us know.

Best regards,
Christian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature requests a new feature Medium Scheduling cron, anacron etc.
Projects
None yet
Development

No branches or pull requests

10 participants