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

nixos/restic: init #38948

Merged
merged 3 commits into from Apr 21, 2018
Merged

nixos/restic: init #38948

merged 3 commits into from Apr 21, 2018

Conversation

Lassulus
Copy link
Member

I'm currently using this to backup my machines. feedback is appreciated, it mostly just satisfies my use-cases.

};
repo = mkOption {
type = types.str;
default = "sftp:backup@prism.r:/backups/${config.name}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all nixos users are connect to retiolum yet. Also the machine would run out of storage.

};
initialize = mkOption {
type = types.bool;
default = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this option idempotent? Can the backup run multiple times when initialize = true; without breaking?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

};
passwordFile = mkOption {
type = types.str;
default = toString <secrets/restic-password>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have no convention on <secrets> in nix path yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should document the "stockholm way" somewhere ;)

@Lassulus Lassulus force-pushed the restic-service branch 2 times, most recently from f90b6c6 to 9404713 Compare April 14, 2018 20:55
@dotlambda
Copy link
Member

You might want to have a look at #36927.

Serving repos would be possible using #38677.

#! ${pkgs.bash}/bin/bash
${resticCmd} snapshots || ${resticCmd} init
'');
ExecStart = pkgs.writeDash "rustic-${plan.name}" (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be writeScript

'');
ExecStart = pkgs.writeDash "rustic-${plan.name}" (
"#! ${pkgs.bash}/bin/bash\n" +
concatMapStringsSep "\n" (dir: "${resticCmd} backup ${dir}") plan.dirs
Copy link
Member

@Mic92 Mic92 Apr 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (readability):

''
#! ${pkgs.bash}/bin/bash
${concatMapStringsSep "\n" (dir: "${resticCmd} backup ${dir}") plan.dirs}
''

@Mic92 Mic92 changed the title restic service: init nixos/restic: init Apr 21, 2018
@Mic92
Copy link
Member

Mic92 commented Apr 21, 2018

tested with:

{...}: {
  services.restic.backups.mybackup = {
    directories = ["/tmp/foo"];
    repository = "/tmp/backup";
    passwordFile = "/etc/nixos/secrets/restic-password";
    initialize = true;
  };
}

@Mic92
Copy link
Member

Mic92 commented Apr 21, 2018

cc @fd0

'';
example = "sftp:backup@192.168.1.100:/backups/${name}";
};
directories = mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you backup single files? I think a name like paths would be more appropriate.

restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
ExecStart = map (dir: "${resticCmd} backup ${dir}") backup.directories;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't restic backup some/file other/file allowed?

type = types.listOf types.str;
default = [];
description = ''
Extra arguments to append to the restic command.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is "appended" (not really) to all restic commands (init and backup), I think it's impossible to add backup-only options like --exclude-caches. That should however be possible.
As it was done for the borg service, I suggest adding extraInitArgs and extraBackupArgs options.

systemd.services =
mapAttrs' (name: backup:
let
extraArguments = concatMapStringsSep " " (arg: "-o ${arg}") backup.extraArguments;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since extraArguments is mapped to -o I think this should be mentioned in the description and the option renamed to extraOptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be each key only specified once?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know about that but when reading extraArguments I think of something like restic --extra-arg.

@Mic92 Mic92 merged commit 6db2057 into NixOS:master Apr 21, 2018
@fd0
Copy link

fd0 commented Apr 21, 2018

Hu? I'm late to the party, is there anything in particular you'd like me to comment on @Mic92?

@Mic92
Copy link
Member

Mic92 commented Apr 21, 2018

@fd0 this was more meant as a general notification. Sometimes upstream developer have valuable input.

@fd0
Copy link

fd0 commented Apr 21, 2018

Cool, thanks for letting me know! NixOS is on my list of things to try :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants