Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to set up a local backup on my desktop system using rdiff-backup and an external harddrive. The backup as such is no problem. I would like to run it as a daily cronjob with anachron, which by itself is also no problem. But I don't keep my computer on, wasting energy, when I don't use it. Sometimes it is possible that I only need to actually use it for a couple of minutes for checking e-mail, then shut it down again. That's also why I want to use anachron, there is no specific time when the computer is definitely on.
I believe this might cause problems with rdiff-backup if the backup cron job is running and I issue the shutdown command. If the cron job gets terminated in the middle, rdiff-backup will log errors.
Now I could write a shutdown script which first checks for a backup process, then waits for it to end before shutdown, but I don't want to fiddle with the shutdown sequence. Shutdown is usually initiated by using the logoff button in Xfce, I don't want to do anything fancy to that (if it is even possible) which I'd have to remember if I switch systems, lose it through an update or whatever.
Is there a way to set up a cron job or a script to enable it to tell the system to wait with shutdown until it is finished?
Or you could have two versions (invocations?) of your back-up script;
one that does the back-up, one that shuts the machine down after
back-up completed. No farting around with checks, cron-jobs or timers.
You choose what it's gonna do before you start it.
That would mean I have to invoke it manually, which is what I am doing now. I want the backup to be a background process managed by anachron so I don't have to start it or mind it.
I have since looked into trapping signals, but there seems to be no way to trap all the signals, sooner or later the shutdown process will issue a kill command and the backup will be stopped ungracefully.
I could write a shutdown script which will only actually shutdown or reboot the system if no backup task is running, but I still wish there was a better way.
You are misunderstanding me; I don't want a backup script which runs then shuts down the system, that's trivial, I want a backup script which gets started automatically as a cron job and will delay a user-initiated shutdown of the system until it is finished.
You are misunderstanding me; I don't want a backup script which runs then shuts down the system, that's trivial, I want a backup script which gets started automatically as a cron job and will delay a user-initiated shutdown of the system until it is finished.
Robin
You need to modify your shutdown to pay attention to the backup. That could be as simple as having your backup script create a sentinel file while it runs; the modified shutdown script would look for that file and hold off while it still exists.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.