Restore a single file using api

63 views
Skip to first unread message

Aurélien Robert

unread,
Aug 31, 2023, 11:37:39 AM8/31/23
to bacularis
Hi,

We are currently testing the restoration of a backup with the bacularis api.
And we can run a full restore job on a backup on another client in a given directory:
curl -X POST https://server/api/v2/jobs/restore --data-raw '{"id":50, "clientid":10, "add_prefix":"/home/user/restore/", "strip_prefix":"/opt/backup/files/", "full":true, "filesetid":25, "restoreclientid":20}' -H 'Content-Type: application/json'

In the web interface restore wizard, we can choose one or a list of files to restore specifically, but it's impossible to find the right way to pass parameters in an api request:
- id looks mandatory?
- full is to be set to false?
- how to pass the path to the file to be restored, e.g. /var/log/bacula/bacula.log (I saw the rpath parameter in the swagger)?

Is this possible?

We've also seen the /api/v2/bvfs/restore endpoint, but haven't succeeded to use it.

Regards,

Aurélien

Marcin Haba

unread,
Aug 31, 2023, 10:09:34 PM8/31/23
to Aurélien Robert, bacularis
Hello Aurélien,

Welcome to the Bacularis user list.

Thanks for sending us your question. The single file restore consists
of the two steps:

1) prepare files in BVFS (/api/v2/bvfs/restore)
2) run restore using BVFS (/api/v2/jobs/restore)

Below you can find the full restore flow to restore two selected
files. I shown there how to go through the directory tree to find
files, how to select files in BVFS and how to run restore.

In case questions, please let us know.

Good luck.

1. Get particular jobids:

GET /api/v2/bvfs/getjobids/?jobid=34835

Response body:
{
"output": [
".bvfs_get_jobids jobid=\"34835\"",
"Using Catalog \"MyCatalog\"",
"34213,34781,34808,34835",
""
],
"error": 0
}

2. Update BVFS cache

PUT /api/v2/bvfs/update

Request body:
{
"jobids": "34213,34781,34808,34835"
}

Response body:
{
"output": [
".bvfs_update jobid=\"34213,34781,34808,34835\"",
"Using Catalog \"MyCatalog\"",
""
],
"error": 0
}

3. List directories in the root directory

GET /api/v2/bvfs/lsdirs/?jobids=34213,34781,34808,34835&offset=0&limit=2000&output=json&path=

Response body:
{
"output": [
{
"pathid": "84772",
"filenameid": "0",
"fileid": "0",
"jobid": "0",
"lstat": null,
"name": "/",
"type": "dir"
}
],
"error": 0
}

4. List directories in / (pathid=84772)

GET /api/v2/bvfs/lsdirs/?jobids=34213,34781,34808,34835&offset=0&limit=2000&output=json&pathid=84772

Response body:
{
"output": [
{
"pathid": "84773",
"filenameid": "0",
"fileid": "0",
"jobid": "0",
"lstat": null,
"name": "..",
"type": "dir"
},
{
"pathid": "84771",
"filenameid": "0",
"fileid": "0",
"jobid": "0",
"lstat": null,
"name": "mnt/",
"type": "dir"
}
],
"error": 0
}

5. List directories in /mnt/ (pathid=84771)

GET /api/v2/bvfs/lsdirs/?jobids=34213,34781,34808,34835&offset=0&limit=2000&output=json&pathid=84771

Response body:
{
"output": [
{
"pathid": "84772",
"filenameid": "0",
"fileid": "0",
"jobid": "0",
"lstat": null,
"name": "..",
"type": "dir"
},
{
"pathid": "30136",
"filenameid": "0",
"fileid": "14838420",
"jobid": "34835",
"lstat": {
"dev": 57,
"inode": 1,
"mode": 16877,
"nlink": 8,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 1008,
"blocksize": 4096,
"blocks": 2,
"atime": 1693388894,
"mtime": 1693457774,
"ctime": 1693457774,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "masmika.pl/",
"type": "dir"
}
],
"error": 0
}


6. List files in
/mnt/masmika.pl/wp-content/themes/twentytwenty/classes/ (pathid=29667)

GET /api/v2/bvfs/lsfiles/?jobids=34213,34781,34808,34835&offset=0&limit=2000&output=json&pathid=29667

Response body:

{
"output": [
{
"pathid": "29667",
"filenameid": "14051407",
"fileid": "14051407",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006305840,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 14817,
"blocksize": 4096,
"blocks": 29,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-customize.php",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051408",
"fileid": "14051408",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006305680,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 6770,
"blocksize": 4096,
"blocks": 14,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-non-latin-languages.php",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051409",
"fileid": "14051409",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006305520,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 1292,
"blocksize": 4096,
"blocks": 3,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-script-loader.php",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051410",
"fileid": "14051410",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006319008,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 502,
"blocksize": 4096,
"blocks": 1,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-separator-control.php",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051411",
"fileid": "14051411",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006218400,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 68568,
"blocksize": 4096,
"blocks": 134,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-svg-icons.php",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051412",
"fileid": "14051412",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006316336,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 65281,
"blocksize": 4096,
"blocks": 128,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-svg-icons.php.orig",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051413",
"fileid": "14051413",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006218592,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 4877,
"blocksize": 4096,
"blocks": 10,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-walker-comment.php",
"type": "file"
},
{
"pathid": "29667",
"filenameid": "14051414",
"fileid": "14051414",
"jobid": "34213",
"lstat": {
"dev": 55,
"inode": 94716006310032,
"mode": 33188,
"nlink": 1,
"uid": 0,
"gid": 0,
"rdev": 0,
"size": 5372,
"blocksize": 4096,
"blocks": 11,
"atime": 1691316220,
"mtime": 1604345315,
"ctime": 1604345315,
"linkfi": 0,
"flags": 0,
"data": 2
},
"name": "class-twentytwenty-walker-page.php",
"type": "file"
}
],
"error": 0
}

7. Prepare files to restore (BVFS restore):

- /mnt/masmika.pl/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-comment.php
- /mnt/masmika.pl/wp-content/themes/twentytwenty/classes/class-twentytwenty-walker-page.php

POST /api/v2/bvfs/restore

Request body:
{
"jobids": "34213,34781,34808,34835",
"fileid": "14051413,14051414",
"path": "b2123456"
}

Response body:
{
"output": [
".bvfs_restore path=\"b2123456\"
jobid=\"34213,34781,34808,34835\" fileid=\"14051413,14051414\"",
"Using Catalog \"MyCatalog\"",
"OK",
""
],
"error": 0
}

8. Run restore

POST /api/v2/jobs/restore

Request body:
{
"client": "darkstar-fd",
"replace": "never",
"restorejob": "Restore Files",
"rpath": "b2123456",
"where": "/tmp/restore"
}

Response body:
{
"output": [
"restore client=\"darkstar-fd\" file=\"?b2123456\"
replace=\"never\" restorejob=\"Restore Files\" where=\"/tmp/restore\"
yes",
"Using Catalog \"MyCatalog\"",
"Bootstrap records written to
/usr/local/bacula/working/darkstar-dir.restore.1.bsr",
"",
"The Job will require the following (*=>InChanger):",
" Volume(s) Storage(s) SD Device(s)",
"===========================================================================",
"",
" *VTL_MAIN_0003_0284 VTL-MAIN Main
Virtual Tape Library",
"",
"Volumes marked with \"*\" are in the Autochanger.",
"",
"",
"2 files selected to be restored.",
"",
"Using Catalog \"MyCatalog\"",
"Job queued. JobId=34852",
""
],
"error": 0
}

Best regards,
Marcin Haba (gani)
> --
> You received this message because you are subscribed to the Google Groups "bacularis" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bacularis+...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/bacularis/533c9e02-b788-4832-90f8-ed3b9d713668n%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
"Greater love hath no man than this, that a man lay down his life for
his friends." Jesus Christ

"Większej miłości nikt nie ma nad tę, jak gdy kto życie swoje kładzie
za przyjaciół swoich." Jezus Chrystus

Aurélien Robert

unread,
Sep 7, 2023, 4:13:41 AM9/7/23
to bacularis
Hello,

Thank you for your precise answer, it works perfectly.
We can now select one or more files to restore without having to run a full restore.

Best regards,
Aurélien

Marcin Haba

unread,
Sep 7, 2023, 10:00:49 PM9/7/23
to Aurélien Robert, bacularis
Hello Aurélien,

Great to hear that it started working on your side.

Thanks for letting us know.

Best regards,
Marcin Haba (gani)

> To view this discussion on the web, visit https://groups.google.com/d/msgid/bacularis/3246c029-7e4c-4692-8008-2967a4ad939en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages