Listing by script the content of archives gives an error when the same command executed interactively not #448
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#448
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi, first thing first: Thank again you for your dedication and this great piece of software that works smoothly for months.
What I'm trying to do and why
I have split my backups in small chunks executed at different moment (day, week month).
Each separate job generates an archive.
I am trying to automate the process of listing the content of each archive file.
To do this, I first extract the list of all archives by executing the command and putting the list in a source file:
borgmatic list --repository repo_path > source_file.txt
Thereafter, I try to list the content of archive by looping through the source_file.txt and executing the following command:
borgmatic list --repository /mnt/borg-repository --archive $archive_var > $archive_var.txt
When I run the command from the command line it runs without any issue.
Doing it thanks to the script I am getting an error:
Here is the script I am using:
Environment
borgmatic version: 1.5.12
borgmatic installation method: docker
Borg version: borg 1.1.15
Python version: Python 3.8.10
Database version (if applicable): psql (PostgreSQL) 13.2
operating system and version: Borgmatic in docker container from b3vis/borgmatic on Unraid server
That output looks strange, either your archive names are missing prefixes like
,
backup-
in your text file or that seems to get lost somewhere for some reason. Thought, thedoes not exist
looks strange already, I would expect the missing part would be placed before or after that message, in the latter case with some:
or alike to distinguish things. I can't finddoes not exist
in this combination in the codebase of Borg as well. Things are especially strange because when youecho
on your own, there seems to be some prefix likebackup-
available.So I suggest printing some additional output here, some lines of the text file your are reading, some lines directly of the borgmatic command output creating the content of the text file etc.
Additionally, try to enable debugging of the shell itself, something like the following in
bash
. Ifash
doesn't provide that, simply trybash
instead.I suggest instead of running
borgmatic
, put anecho
in front to see the actually rendered command line as well:Besides all of that, using a more current version of BorgMatic might be an option as well.
Hello,
Thank you for taking time to provide me some support.
Please here is the echo of the command:
As a test, I took the last line of the echo and executed it as is. And it went successfully.
Hereunder you find an extract of my source file:
Here is an extract of the error with the additional parameters you provided. I currently am not able to use those parameters with bash as the container is compiled with ash:
Your proivided output doesn't make too much sense: The archive names used in your first quoted commands are NOT present in what you say is the source file you are basing your script on. OTOH, the source files contains multiple columns of output, while your script does NOT seem prepared to process multiple columns, but only one line with one column instead.
So either you mixed something totally up somewhere or are only showing some excerpts and the spaces-divided columns in your source file are the problem already. The latter might make even sense with the error message:
There might be one of the spaces of your source file which is not present.
A couple of additional questions:
borgmatic_list_jobcontent.sh
correspond with the script containingjob_unit
pasted above? If so, how doesjob_unit
end up getting set? Are values piped intoborgmatic_list_jobcontent.sh
? If so, can we see that full invocation including the values passed in?Thanks! I appreciate your patience here.
Hi,
I think I replied a little bit in a rush and messed up my answer.
So let's start with the purpose of the script.
I have a borgmatic container executing different jobs based on cron jobs. Roughly, there are 3 types of jobs:
For each type of job there are preparation and ending operations (stop container/vm, check, backup, check restart container/vm). Based on the criticality of the data the jobs are executed more or less frequently. For the "files and folders" type, the job is executed everyday.
Each job is named with a basic naming convention (backup-2021-07-20T05:13:56). Maybe I should already start naming the jobs by adding the job type in the name.
The problem: When I want to restore a specific file or folder I need to know which archive needs to be provided.
Currently, I am not able to do this because I have a very long list of archives which will constantly increase everyday.
My idea was to generate automatically a library containing the archives names and its content to be able to index and search through it.
To proceed with this idea, I created a script which outputs the list of all archives in a source file (job_list.txt).
For what concerns the source file, I agree there was one step I omitted to mention: I removed the useless columns on the right. Sorry for that.
In a second stage, I take the job_list.txt and parse the file using each line (job_unit) to build a new borgmatic command to output the content of each archive represented by the job_unit.
borgmatic --verbosity 2 list --repository /mnt/borg-repository --archive "$job_unit" > "$job_unit.txt"
When I execute the command manually it works perfectly. In borg and borgmatic
When I echo the exact command I get the error shown above.
When I remove the file redirection of the command and echo it, I get it working
I tried the same with bash and with borg. Get the same error and same success.
It's still not clear to me what your are executing when, it additionally seems you seem to change what gets executed with each comment. E.g. the redirection
> "$job_unit.txt"
wasn't mentioned before? This can't be debugged under those circumstances, so I suggest taking a step back and look at what you said before:Not only that: Am I understanding correctly that you use one repo only to store all data? Then I suggest changing that to one repo per job type. The data of the different jobs will most likely be that different, that you won't get too much benefit of de-duplication within one and the same repo anyway. Use one repo for docker, one for VMs and one for individual files and folders of interest. Depending on the actual backed up data, you can additionally name archives by customers or alike. With that approach you always know which repo contains your files and folders of interest and only care about the concrete archive to restore.
In the easiest case, you wouldn't need to maintain some index at all only to work around your "one repo to rule them all"-approach.
Dear,
Thank you for your time and your answer. I certainly will take your proposal into account and review the architecture of my backups.
Concerning your remark about the redirection it was mentionned in the begining of the post "borgmatic list --repository /mnt/borg-repository --archive $archive_var > $archive_var.txt"
As an additional remark I think I found the source of the problem, it is linked to a special character located at the end of the source file which caused the issues. This is very strange and the errors raised did not easily helped to pinpoint it.
Thanks again for your help and support.
Denis
I'm glad to hear you've found the source of the problem! You may already be aware of the feature, but borgmatic accepts "latest" as an archive name, which will select the most recent archive in a repository. I don't know if that's of use for your particular use case, but it could be useful if you switch to a separate repository per backup source. In any case, if you have any further issues, please feel free to file another ticket! And thanks for using borgmatic.