I use a 6 GB seagate drive exclusively for backups. Those are triggered automatically by backintime right after bootup. After that the drive is not in use during a normal session. I want to run “sudo hdparm -y /dev/sda” after the backup is done (backintime is a frontend for rsync). So I created a file in “/etc/systemd/user/graphical-session-pre.target.wants/”
[Unit]
Description=Spin down /dev/sda after backup via backintime / rsync
After=graphical-session-pre.target
…where /usr/bin/spin-down-sda.service is an executable script with only the line “sudo hdparm -y /dev/sda”.
But after looking at it it doesn’t seem right. But I have no better idea. I tried the archwiki but that didn’t work either, I am too new to that kind of scripting(?). Any ideas here? Thanks.
What is the use of sudo here? The systemd service already runs “as root”, thus it’s child process will do the same.
That is, you should of course run the backup as a system service.
I decent script starts with a “shebang” that defines what interpreter should be used. Like
#!/usr/bin/bash
and thus has at least two lines.
But I guess the main problem is when the service should run.
Can you provide the definition of your backup service?
And last, please do not use the Blockquote (") button, but the Preformatted text (</>) button when posting code.
You are right of course. I already added the shebang and removed “sudo”.
Sorry for the wrong formatting, didn’t know better.
But I guess the main problem is when the service should run.
Backintime is running right after logging in is done. When its exits (successfully) I want the hard disk to spin / shut down.
Can you provide the definition of your backup service?
This is no systemd service as far as I know. I’m not aware that backintime is handled by systemd. I had hoped to be able to find out when rsync / backintime ends and then start the little script to spin / shut down the drive.
Well, that is a bit strange. I do not know backintime, but somewhere you must have configured it. And also when it should run. You say “after logging is done”. but logging is done all the time by a lot of components. So that is confusing to me.
In my opinion the best way to go is to find out where the starting mechanism is and what is run then. It would be nice if you could then simply add your command at the ed of such a found script.
But maybe we need someone here who knows more about the backintime internals.
Sorry to be back so late, there were problems to log in into the forums…
@ malcolmlewis
That looks interesting, I didn’t know that there was a possibility already preformed in backintime (git). I will have to try that and come back with the results. One more thing though: the command for backintime in crontab is currently
#Back In Time system entry, this will be edited by the gui: @reboot /usr/bin/nice -n19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime backup --background >/dev/null
I did not find a substitute for that @reboot for systemd. Do you have an idea?
@ hcvv
Ah, I wrote “logging in” meaning to log in, not logging results of processes…
You seem to hav a crontab entry to start it after boot. That has nothing to do with login of any user.
But again, why do you not SHOW anything. Show that crontab entry then we all know what we are talking about.
And you can of course change the to be run command of the crontab entry into something like /root/bin/mybackup
and then create /root/bin/mybackup with a contents:
#!/usr/bin/bash
the original command from the crontab
/usr/bin/spin-down-sda.service
Or you go for a systemd timer function, which then also best calls your script in the ExecStart stanza.
@ hcvv
Umm, the crontab line is right in my post before yours…
But that is another damn fine idea to expand the existing crontab entry, thanks.
@ malcolmlewis
I don’t need to restart the machine. Currently crontab just starts backintime right after boot / login. That is what I wanted to do also with systemd.
Sorry, I missed that because it was a Quote (")and not Preformatted text (</>) as code should be. Also there was no command included (we normally need the code complete: prompt-command line, all output, next prompt). Thus I skipped that as it being “just from somewhere”.
I tried it via crontab – to no avail. This is my crontab:
#Back In Time system entry, this will be edited by the gui:
@reboot /usr/bin/nice -n19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime backup --background >/dev/null
@reboot /usr/bin/spin-down-sda
And this is /usr/bin/spin-down-sda:
matthias@ryzen:~> ll /usr/bin/spin-down-sda
-rwxr-xr-x. 1 root root 35 6. Jun 19:27 /usr/bin/spin-down-sda
I recommended to create a script somewhere (my suggestion: /root/bin) and put the two statements in that script.
And then call that script from the crontab instead of the backintime command you have now.
Also:
Again that is NOT the way you should report. You report starting with the prompt/command line, then all output and then the new prompt.
In this case it could be
crontab -l
or
cat /etc/crontab
or
…
We are NOT clairvoyant and you have to show us in every detail what you do and have.
BTW, as said earlier, I do not much about Backintime or what it does. But when it backups to some file system (on the disk you want to spin down) then it probably writes to one or more file system(s) on that disk. Thus before spinning it down, those file system(s) must be unmounted. When Backintime does not do that, you must do that.
You have two crontab entries that start at the same time. Thus you want to make a backup to a file system on a device that you try to spin down at the same time. I guess that is indeed a mistake in understanding the sequence of execution in a multi-process (and multi processor) system.
Instead of using /sbin/hdparmas command in the second crontab entry, you execute a script in/usr/bin that does not belong there. Why this indirection? It will work, but you are interfering, unneeded, with the convention of the placement of system software. I consider this a mistake.
I can only repeat that making one and only one script that contains the complete way of doing the backup is the best thing to do. That is also easy to change without changing the crontab entry at all.
Again I suggest the bin directory in the home directory of root for this: /root/bin/.