# LocalBackup

Required Frends version: 5.1+

Required .NET version: 471, 6.0, standard2.0

Compatible Agents: Legacy, Crossplatform

Source code: <https://github.com/FrendsPlatform/Frends.Files/tree/main/Frends.Files.LocalBackup>

{% tabs %}
{% tab title="Parameter: Input" %}

| Name                             | Description                                                                                                                                                                                                                                                                                                                           |                                                               |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| SourceDirectory : `String`       | <p>Source directory.</p><p><br>Default: <code>-</code><br>Example: <code>c:\temp</code></p>                                                                                                                                                                                                                                           |                                                               |
| SourceFile : `String`            | <p>Source file. The file mask uses regular expressions, but for convenience, it has special handling for \* and ? wildcards.</p><p><br>Default: <code>-</code><br>Example: <code>test.txt, test\*.txt, test?.txt, test.(txt                                                                                                           | xml), test.\[^t]\[^x]\[^t], ^(?!prof).\*\_test.txt</code></p> |
| FilePaths : `Object`             | <p>The paths to the files to be backuped, mainly meant to be used with the file trigger with the syntax: #trigger.data.filePaths</p><p>FilePaths will overwrite SourceDirectory and SourceFile parameters.</p><p><br>Default: <code>-</code><br>Example: <code>#trigger.data.filePaths</code></p>                                     |                                                               |
| BackupDirectory : `String`       | <p>Destination directory where backup folder will be created. Backup directory's format if CreateSubdirectories=true: {BackupDirectory}{timestamp}-{Guid}.</p><p><br>Default: <code>-</code><br>Example: <code>c:\temp\backups, c:\temp\backups\</code></code></p>                                                                    |                                                               |
| CreateSubdirectories : `Boolean` | <p>Create a subdirectory into the given backup directory.</p><p><br>Default: <code>True</code><br>Example: <code>true</code></p>                                                                                                                                                                                                      |                                                               |
| TaskExecutionId : `String`       | <p>Enabled when (Create Subdirectories) is true. Value which is used in naming the backup directory. Can be any string but using task's execution id as default to avoid duplicate directory names.</p><p><br>Default: <code>#process.executionid</code><br>Example: <code>e7e34166-f4fd-45e5-9307-ea5c2cf8e037, foobar123</code></p> |                                                               |
| Cleanup : `Boolean`              | <p>Cleanup older than {DaysOlder} folders from backup directory.</p><p>If Create Subdirectories is false, individual files will also get cleaned.</p><p><br>Default: <code>-</code><br>Example: <code>false</code></p>                                                                                                                |                                                               |
| DaysOlder : `Int32`              | <p>Clean up backups older than given value in days. Enabled when {Cleanup} is true.</p><p><br>Default: <code>-</code><br>Example: <code>30</code></p>                                                                                                                                                                                 |                                                               |
| {% endtab %}                     |                                                                                                                                                                                                                                                                                                                                       |                                                               |

{% tab title="Result: Result" %}

| Name                        | Description                                                                                                                                                                                                                                                                                                                                                                                                   |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Directory : `String`        | <p>Backup directory.<br>Example: <code>C:\directory\backup\2022-07-07\_08\_51\_02-e7e34166-f4fd-45e5-9307-ea5c2cf8e037</code></p>                                                                                                                                                                                                                                                                             |
| FileCountInBackup : `Int32` | <p>Count of files which were copied to backup directory.<br>Example: <code>1</code></p>                                                                                                                                                                                                                                                                                                                       |
| Backups : `List<String>`    | <p>Backup results as list of strings.<br>Example: <code>"Backups": \[ "Backup complete: C:\test\localbackup\test - Copy (2).txt to C:\test\backup\2022-07-07\_08\_51\_02-e7e34166-f4fd-45e5-9307-ea5c2cf8e037\test - Copy (2).txt", "Backup complete: C:\test\localbackup\test - Copy (3).txt to C:\test\backup\2022-07-07\_08\_51\_02-e7e34166-f4fd-45e5-9307-ea5c2cf8e037\test - Copy (3).txt" ]</code></p> |
| Cleanups : `List<String>`   | <p>Cleanup results as list of strings.<br>Example: <code>"Cleanups: \[ "C:\test\backup\2022-07-11\_05\_44\_41-ab214387-98f0-44de-8ec5-16ba01b8ab97 deleted.", "C:\test\backup\2022-06-25\_06\_23\_56-ab214387-98f0-44de-8ec5-16ba01b8ab97 deleted." ]</code></p>                                                                                                                                              |
| {% endtab %}                |                                                                                                                                                                                                                                                                                                                                                                                                               |

{% tab title="Changelog" %}

## Changelog

### \[2.2.0] - 2025-03-19

#### Changed

* Update packages: System.ComponentModel.Annotations 4.7.0 -> 5.0.0 coverlet.collector 3.1.0 -> 6.0.4 Microsoft.NET.Test.Sdk 16.6.1 -> 17.13.0 MSTest.TestAdapter 2.2.7 -> 3.8.3 MSTest.TestFramework 2.2.8 -> 3.8.3 nunit 3.12.0 -> 4.3.2 NUnit3TestAdapter 3.17.0 -> 5.0.0

### \[2.1.3] - 2024-01-16

#### Fixed

* Fixed how FilePaths were handled. Changed casting to string\[] to convert the object into a string\[] by casting it first as a object\[].

### \[2.1.2] - 2023-08-31

#### Fixed

* Fixed bug in CreateBackup which was caused by Task not been able to delete the directory if there are directories present.

### \[2.1.1] - 2023-08-08

#### Fixed

* Added check for implicit match for the file and filemask.

### \[2.1.0] - 2023-05-31

#### Added

* Added parameter for FilePaths. If FilePaths is used it will overwrite the SourceDirectory and SourceFile parameters.

### \[2.0.4] - 2023-05-09

#### Fixed

* Fixed issue where Cleanup adds deleted message even if files were not deleted.

### \[2.0.3] - 2022-11-25

#### Fixed

* Fixed issue when using CreateSubdirectories Cleanup uses same directory which is created in Backup and when there's no files to backup the directory is deleted and cleanup won't find the directory.

### \[2.0.2] - 2022-10-13

#### Changed

* Cleanup will clean individual files in addition to directories when CreateSubdirectories is false.

### \[2.0.1] - 2022-09-13

#### Added

* Added CreateSubdirectories input which gives the user an option to choose whether to create a backup into a given (BackupDirectory) or create a new folder with a name generated by task into (BackupDirectory).

#### Changed

* Cleanup change: Directory to be deleted is determined by timestamp in directory name when (CreateSubdirectories) is true, else by directory's LastWriteTime value.

### \[2.0.0] - 2022-07-11

#### Added

* Modified the task to use #process.executionid instead of a random guid
* \[Breaking change] Added input for TaskExecutionId as guid
* Added backup directory value to Result object
* Added file count how many were made backup of
* \[Breaking change] Removed BackupObject class and changed the result object to have list of string for backup and cleanup

### \[1.0.0] - 2022-05-16

#### Added

* Initial implementation
  {% endtab %}
  {% endtabs %}
