Commit Graph

187 Commits

Author SHA1 Message Date
Fiona Ebner
573e832067 vzdump: send mail if job-abort hook fails
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-11-16 11:25:58 +01:00
Fiona Ebner
268c642826 fix #4351: vzdump: send mail if job-end hook fails with mailnotification=failure
Since all tasks succeeded, previously no mail was sent in that case.

Note that the error passed to $self->sendmail() is added to the
subject of the mail if it is a single line or the beginning of the
mail otherwise. Thus changing the mail slightly compared to previously
for the case where the job-start hook fails and the case where the
job-end hook fails with mailnotification=always. But can be considered
an improvement, because the user sees the error right away.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-11-16 11:25:58 +01:00
Fiona Ebner
93880785c8 vzdump: handle new 'performance' property string
Also generalizes the way vzdump property strings are handled for jobs.
Something similar could be done in VZDump.pm, but there the maxfiles
and prune-backups settings are currently coupled, so a dedicated
parse_performance() is used instead. Can be changed once maxfiles is
dropped.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-10-10 13:04:17 +02:00
Fabian Ebner
3f488b618b vzdump: avoid 'requires' constraint when parsing defaults
to avoid warnings like
parse error in '/etc/vzdump.conf' - 'storage': missing property -
'notes-template' requires this property
when there is no default for the required property configured.

In new(), the defaults are mixed in with the regular CLI/API
parameters, so re-check if the required property is set. If it's not,
the defaults do not apply to the current run, and can be dropped.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-05-12 17:17:56 +02:00
Fabian Ebner
2078e35988 vzdump: generate notes: initialize potentially undef values
For VMs, $task->{hostname} might be undef and when running on a
stand-alone node, there is no cluster name.

Reported-by: Marco Gabriel <mgabriel@inett.de>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-05-12 17:17:56 +02:00
Fabian Ebner
facf65a6e0 vzdump: verify parameters: properly verify notes-template
instead of just checking for a newline, do a full check already.

Also do the check at the beginning of generate_notes() for consistency
and remove the check after expansion to avoid failing late for things
like '{{cl{{node}}er}}' (which can even expand to a valid variable
making the error even more confusing).

Co-developed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-05-12 17:17:48 +02:00
Thomas Lamprecht
d0dfd9b87f vzdump: fix unknown variable name error, add newline
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-05-04 08:19:35 +02:00
Fabian Ebner
1f581ff78e vzdump: notes-template: improve check for unknown variable
so that '{{foo}}{{bar}}' is not detected as being an unknown variable
named 'foo}}{{bar', but as 'foo' (and 'bar').

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-05-04 07:58:50 +02:00
Fabian Ebner
4ed6e1b182 vzdump: notes-template: avoid escaping meta-characters upon replace
which is caused by the quoting operators \Q...\E. The actual intention
was to avoid such surprises.

Fixes: e01438a7 ("partially close #438: vzdump: support setting notes-template")
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-05-04 07:57:45 +02:00
Thomas Lamprecht
0ac20586ac vzdump: transform hook script checks to post-if notation
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-04-28 18:44:20 +02:00
Dylan Whyte
941ed98edd vzdump: add error if passed in hook script doesn't exist
Previously, if the '--script' argument was passed with a non-existent
file, it would state that a non-executable script was the reason for
failure. This adds a check to see if the hook script exists, in order
to provide a more accurate error message.

Also adds an 'Error:' prefix the 'script not executable' error.

Signed-off-by: Dylan Whyte <d.whyte@proxmox.com>
2022-04-28 18:38:53 +02:00
Fabian Ebner
010ff16e9f vzdump: check that notes-template is a single line
While vzdump itself wouldn't mind about unescaped newlines, the
parameter isn't supposed to contain any, and when used as part of the
job config, it has to be a single line too, so make it consistent.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-28 14:16:33 +02:00
Fabian Ebner
31213d61d3 vzdump: generate notes: die upon unexpected escape character or variable
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-28 14:16:33 +02:00
Fabian Ebner
e01438a744 partially close #438: vzdump: support setting notes-template
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-28 13:45:53 +02:00
Fabian Ebner
bbd4cdd845 vzdump: support setting protected status
Check the number of protected backups early if the protected flag
is set.

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-27 11:37:26 +02:00
Fabian Ebner
c527d28f0c fix #3955: vzdump: new: also send mail for error during job-init hook
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-27 10:36:19 +02:00
Fabian Ebner
3c5a7616cf vzdump: new: add add_error helper
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-27 10:36:19 +02:00
Fabian Grünbichler
725c0555d2 vzdump: always pass full list to prune marking
else this single call site is subtly different from all the rest, which
could cause problems further down the line if we ever change the prune
logic.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-04-06 14:07:21 +02:00
Fabian Ebner
7bffbd2241 vzdump: backup limit: only count unprotected backups
since they are the ones relevant for pruning and protected backups
have their own separate limit.

Since get_backup_file_list is only used in places where the
unprotected backups are needed, adapt the helper accordingly.

If there is a storage, use PVE::Storage::volume_list to count the
unprotected backups. This avoids a direct invocation of the
proxmox-backup-client for PBS and the limit check can also work for
external storage plugins which might not be dir-based or name the
backups differently.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-06 13:40:05 +02:00
Fabian Ebner
0a9ca6caf6 vzdump: backup file list: drop unused parameter
It's not used anymore since 77c7945123
aligned pruning in a dumpdir with pruning on a storage.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-04-06 10:00:34 +02:00
Fabian Ebner
b241deb731 close #3476: vzdump: add job-init hook
which allows users to prepare the backup storage for activation (e.g.
by waking up a remote node).

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Acked-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-01-18 12:20:26 +01:00
Fabian Ebner
2fc939a94d vzdump: skip protected backups for dumpdir pruning
Keeps the behavior consistent with what happens for storages. It also
is required to not get into conflict with the check in archive_remove,
i.e. pruning here marks a backup as 'remove' and then archive_remove
complains that it's protected.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-11-09 11:33:16 +01:00
Fabian Ebner
f332a16745 vzdump: pbs: suppress output from upload-log command
which ended up in the backup task log and can be confusing to users:

> INFO: Backup finished at 2021-10-11 08:40:38
> Result: {
>       "data": null
> }
> INFO: Backup job finished successfully

For proxmox-backup-server < 2.0.11-1, there was no output for the
upload-log command.

Reported in the community forum:
https://forum.proxmox.com/threads/backup-finishes-ok-but-data-null-info-on-finish.97740/

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-10-11 09:51:24 +02:00
Fabian Ebner
77c7945123 vzdump: include current backup when pruning dumpdir
Not doing so leads to an off-by-one error, and pruning in a dumpdir
really should behave the same way as pruning in a storage.

Reported in the community forum:
https://forum.proxmox.com/threads/problem-mit-prune-backups.95737/

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-09-08 12:58:53 +02:00
Oguz Bektas
dfc62e829c vzdump: allow backups from plugins
remove type check for the specific plugins, instead we can deduce it
from the supported content type in config (this can only be set on
storages that declare to support backups). should also work with
external storage plugins.

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
2021-07-30 17:08:58 +02:00
Thomas Lamprecht
ff119724ee vdzump: whitespace/extra-lines clean up
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-06-18 14:35:25 +02:00
Thomas Lamprecht
b4546c7ec2 vzdump: log the count of backups we pruned#
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-06-18 13:31:27 +02:00
Thomas Lamprecht
4922b7a91c vzdump: make log for stop-mode guest-type agnostic
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-06-18 13:24:47 +02:00
Thomas Lamprecht
ca155141b0 vdzump: log with what retention settings we prune
may not be obvious from the task log alone if we're relying on the
retention setting configured on a storage or the ones from local
node's vzdump.conf

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-06-17 17:55:54 +02:00
Fabian Ebner
2cacb88049 Revert "VZDump: add TARFILE to environment for hookscripts"
This reverts commit 5d0d14f179.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-06-09 10:08:58 +02:00
Fabian Ebner
173f8c49ef vzdump: remove deprecated size parameter
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-06-08 15:22:52 +02:00
Fabian Grünbichler
58f763e1aa fix #3430: handle hook script paths better
if passing the hook script command as string, it might get interpreted
as shell command with side-effects. this is pretty harmless, since only
root is allowed to set the script parameter anyway, but making it more
robust and future-proof does not hurt.

tested with a reproducer of "/bin/echo $(touch $(whoami))" as script
parameter, with a file with that name existing, being executable and
having the following contents:

----8<----
echo "hello from hook script"
---->8----

without this change, the hookscript itself is not executed, but
'/bin/sh -c "/bin/echo $(touch $(whoami)) job"' and similar calls are,
which cause the file 'root' to be touched in the current working
directory of the vzdump process (or task worker).

with this change, the file is executed as is without any side-effects of
shell commands in the file name, and the 'hello from hook script' lines
are printed whenever the hook script is called by vzdump.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-05-17 09:49:34 +02:00
Fabian Ebner
875c2e5aae vzdump: getlock: return lock file handle and let the caller close it
so it doesn't get out of scope too early.

Regression introduced by 5620e5761e as pointed
out by Fabian Grünbichler.

Reported in the community forum:
https://forum.proxmox.com/threads/limit-simultaneous-backup-jobs.87489

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-04-12 14:36:08 +02:00
Fabian Ebner
164651dab6 vzdump: storage info: move out activate storage call
Otherwise storage_info() cannot be used for (at least) PBS storages from an API
call without 'protected => 1', because the password cannot be read from
'/etc/pve/priv'. Note that the function itself does not need the storage to be
active, because it only uses storage_config() and get_backup_dir().

AFAICT new() is the only existing user of this function and can be responsible
for activating the storage itself.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-03-31 15:40:13 +02:00
Fabian Ebner
914e86ccbd partially fix #2745: vzdump: use default for remove parameter
The initial default from the $confdesc is 1 anyways, and like
this changing the default in /etc/vzdump.conf to 0 actually works.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-03-05 21:31:32 +01:00
Thomas Lamprecht
1353489ed2 vzdump: indentation and whitespace fixes
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-25 19:21:18 +01:00
Thomas Lamprecht
94009776df vzdump: avoid single argument bless
reported by perlcritic.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-25 19:19:15 +01:00
Thomas Lamprecht
5620e5761e vzdump: avoid bareword file handles and two argument open
reported by perlcritic. The bareword file handles will be depreacated
in the future in perl, so start replacing now..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-25 19:17:42 +01:00
Thomas Lamprecht
e8d9e1ed17 vzdump: PBS: make task log upload error non-fatal
We want to continue in that case, this is not really essential so
only warn about it.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-25 13:59:45 +01:00
Fabian Ebner
f8ed6af80d vzdump: refactor parsing mailto so it can be mocked
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-02-19 16:33:33 +01:00
Fabian Ebner
ecc08c34ea vzdump: avoid parsing already parsed option
When a job is updated, verify_vzdump_parameters() is called twice. This led to
parse_property_string being called with the already parsed option.

Reported on the pve-user mailing list:
https://lists.proxmox.com/pipermail/pve-user/2021-January/172258.html

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2021-01-26 18:47:48 +01:00
Fabian Ebner
5a9b791b47 vzdump: fix error format for errors coming from storage_info
Errors from storage_info() are newline-terminated, because perl would append
the line number otherwise. Chomp those errors, because sendmail() relies
on the presence of a newline to decide if it's multiple problems or only one.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-21 15:29:02 +01:00
Fabian Ebner
213e0eb263 vzdump: sendmail: fix html by closing the tags
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-21 15:29:02 +01:00
Fabian Ebner
dd5d80f56a vzdump: defaults: convert to prune-backups early enough
Fixes the case where reading from /etc/vzdump.conf fails.

Also convert the options read from /etc/vzdump.conf before the loop. That
avoids showing a wrong warning when 'prune-backups' is configured in
/etc/vzdump.conf, and maxfiles isn't. Previously, because 'maxfiles' from the
schema defaults was automatically set, the call to parse_prune_backups_maxfiles
after the loop threw the warning that both options are defined.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-21 15:29:02 +01:00
Fabian Ebner
fb6871fc7f vzdump: use debugmsg instead of warn
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-07 09:31:12 +01:00
Fabian Ebner
f1dd762969 vzdump: warn when both storage and dumpdir are defined in vzdump.conf
and prefer storage, because the storage configuration might contain more
settings. Warning is preferable over dying, because all backups would be
affected (even if they don't use the vzdump.conf parameters) and the settings
could've been compatible (i.e. dumpdir being the storage's dump dir). Previously
one of the two options would randomly be chosen in the loop in new(), because of
perl hash iteration.

Reported here: https://forum.proxmox.com/threads/vzdump-times-out-very-often-on-zfs-storage-pool.80035/post-354277

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-07 09:31:12 +01:00
Fabian Ebner
acc963c3e5 vzdump: defaults: correctly parse prune-backups and convert maxfiles
Also simplify handling in new(), now that we never have maxfiles there anymore.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-02 13:15:52 +01:00
Fabian Ebner
1c56bcf39d vzdump: convert maxfiles CLI parameter to prune-backups
in preparation to clean up handling in new().

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-02 13:15:52 +01:00
Fabian Ebner
e2aac8cc8c vzdump: storage_info: adapt to new maxfiles backend behavior
It's automatically converted to prune-backups when using storage_config() now.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-12-02 13:15:52 +01:00
Fabian Ebner
b63baa391c cleanup keep-all handling
If keep-all is set to 0, adding it doesn't make a difference,
if the key is not in the hash, it won't show up in the 'values'.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2020-11-23 16:03:08 +01:00