# IRPCVaultAdmin.ArchiveOldVersions

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Administration API](https://developer.m-files.com/APIs/gRPC-API/admin/index.md) > [Vault administration](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCVaultAdmin/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCVaultAdmin/ArchiveOldVersions/

Badges: `Administration API / specialized` `admin` `session`

Archives old versions of documents that meet the job's conditions into an archive file on the
server, or previews how many would be archived.

- **Service:** [Vault administration](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCVaultAdmin/index.md) `MFiles.IRPCVaultAdmin`
- **gRPC method:** `/MFiles.IRPCVaultAdmin/ArchiveOldVersions`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/archive-old-versions`
- **Request:** [`ArchiveOldVersionsRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCVaultAdmin/ArchiveOldVersions/index.md#request)
- **Response:** [`ArchiveOldVersionsResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCVaultAdmin/ArchiveOldVersions/index.md#response)
- **Book and level:** Administration API, specialized
- **Kind:** admin
- **Session:** Required: the session ID from LogIn in the mfiles-session-id-bin metadata.
- **Idempotent:** no
- **Returns metadata structure version:** no
- **Streaming:** none (unary)

<a id="remarks"></a>

## Remarks

- **Starts a background job and returns before it completes** unless `preview_only` is true;
  follow it with a session of this vault (see the service overview). A preview runs within the
  call and changes nothing.
- Requires a vault session and the vault right `archive`. Running the job for real (not a preview)
  also needs the server right `manage_jobs`; without it the call fails with "Access denied". For
  callers without that right, leave `archivejob.target_file` empty also in a preview.
- Fails on M-Files editions that do not include archiving.

<a id="request"></a>

## Request: ArchiveOldVersionsRequest

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `preview_only` | `bool` | True to only count what would be archived; the destination in the job is then ignored and nothing changes. False to start the archiving job. |
| `archivejob` | [`ArchiveOldVersionsJob`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ArchiveOldVersionsJob/index.md) | The conditions that select the old versions, the target file on the server and the archiving options. |
| `archivejob.must_be_marked_for_archiving` | `bool` | Condition: Document is marked for archiving. False = condition not effective. |
| `archivejob.must_be_checked_in_before_utc` | [`google.protobuf.Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp) | If bCheckedInBefore is true, specifies the condition parameter. |
| `archivejob.has_must_be_at_least_nversions_older` | `bool` | Condition: At least N versions older than the current version. False = condition not effective. |
| `archivejob.must_be_at_least_nversions_older` | `int32` | If bAtLeastNVersionsOlder is true, specifies the condition parameter. |
| `archivejob.has_must_be_at_least_ndays_older` | `bool` | Condition: At least N days older than the current version. False = condition not effective. |
| `archivejob.must_be_at_least_ndays_older` | `int32` | If bAtLeastNDaysOlder is true, specifies the condition parameter. |
| `archivejob.must_not_have_version_tag` | `bool` | Condition: Has no version tag. False = condition not effective. |
| `archivejob.target_file` | `string` | Full path to the target file on server. |
| `archivejob.impersonation` | [`Impersonation`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.Impersonation/index.md) | Impersonation information for accessing the archive target files on server. |
| `archivejob.impersonation.type` | [`ImpersonationType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.ImpersonationType/index.md) | Impersonation type. Values: `IMPERSONATION_TYPE_SYSTEM_ACCOUNT` (0), `IMPERSONATION_TYPE_LOCAL_WINDOWS_ACCOUNT` (1), `IMPERSONATION_TYPE_EXTERNAL_ACCOUNT` (2). |
| `archivejob.impersonation.account` | `string` | Account name (e.g. DOMAIN\user). |
| `archivejob.impersonation.encrypted_password` | `bytes` | Encrypted password. |
| `archivejob.options` | [`OBJARCHIVINGFLAGS`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.OBJARCHIVINGFLAGS/index.md) | Bit flags that control the execution of this archiving job. Note: Currently only OBJARCHIVINGFLAG_OVERWRITEEXISTINGFILES, OBJARCHIVINGFLAG_DESTROYAFTERWARDS, and OBJARCHIVINGFLAG_RESETMFA are supported. |
| `archivejob.options.all` | `bool` | Specifies all flags set; Including any future flags. |
| `archivejob.options.overwrite_existing_files` | `bool` | If present, existing target files are overwritten. If not present, job fails if a target file already exists. |
| `archivejob.options.archive_latest_version_only` | `bool` | If present, only the latest version is archived. |
| `archivejob.options.destroy_archived_objects` | `bool` | If present and archiving full objects, the archived objects are destroyed. |
| `archivejob.options.reset_marked_for_archiving` | `bool` | If present, the 'Marked for archiving' property is reset upon archiving. |
| `archivejob.options.archive_data_files` | `bool` | If present, data files are archived instead of document files. |
| `archivejob.options.create_archive_pdfs` | `bool` | If present, files are also saved as PDF/A. |
| `archivejob.options.archive_destroyed_objects` | `bool` | If present, destroyed objects are archived. |
| `archivejob.options.target_path_is_directory` | `bool` | If present, archive location represents a directory. |
| `archivejob.options.ignore_last_run_timestamp` | `bool` | If present, delta timestamp is not applied (even if provided as non-FILETIME_ZERO). |
| `archivejob.options.ignore_search_conditions` | `bool` | If present, search filter is not applied (even if provided). |
| `archivejob.options.export_drop_out_information` | `bool` | If present, dropout information is exported if a previously exported object is not anymore part of the export set. |
| `archivejob.options.export_content` | `bool` | If present, vault content will be exported. |
| `archivejob.options.export_structure` | `bool` | If present, vault metadata structure will be exported. |
| `archivejob.options.export_value_list_values` | `bool` | If present, values of the selected values lists will be exported. |
| `archivejob.options.export_private_view_settings` | `bool` | If present, private settings of the selected views will be exported. |
| `archivejob.options.export_migrated_as_internal` | `bool` | If present, migrated objects will be exported as internal objects without <externalrepository> element. |
| `archivejob.options.export_workspace_tabs` | `bool` | If present, workspace tabs will be exported. |

<a id="response"></a>

## Response: ArchiveOldVersionsResponse

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `task_id` | `int32` | The ID of the vault's archiving job when `preview_only` is false. |
| `parchiveoldversjoboinfo` | [`ArchiveOldVersionsJobOutputInfo`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ArchiveOldVersionsJobOutputInfo/index.md) | The preview result when `preview_only` is true: affected documents, versions and bytes. |
| `parchiveoldversjoboinfo.objects` | `uint32` | The number of affected documents. |
| `parchiveoldversjoboinfo.object_versions` | `uint32` | The number of archived document versions. |
| `parchiveoldversjoboinfo.bytes` | `int64` | The amount of archived bytes. |
