trim_backups: Remove Files from Directory Based on Date Created

trim_backupsR Documentation

Remove Files from Directory Based on Date Created

Description

trim_backups() deletes old backup files from a directory. More specifically, it identifies files in a directory with a common naming pattern and it keeps the most recent of those files. To be deleted, a file not be one of the min_backups newest files, and it must be older than min_date. This ensures that at least min_backups backups are always retained while keeping any additional backups created on or after min_date. The defaults are chosen so that at least 7 backups over at least the past 7 days are kept.

Usage

trim_backups(
  directory,
  pattern = NULL,
  min_backups = 7,
  min_date = Sys.Date() - min_backups + 1
)

Arguments

directory

The path to the backup directory

pattern

The naming pattern of the backup files, as a regular expression. This allows maintenance of backups when other files are also present in the directory (though this is not recommended).

min_backups

The minimum number of backups to keep

min_date

The date after which to keep all backups. The default is set to keep files for min_backups days.

Value

The deleted paths (invisibly)


jesse-smith/coviData documentation built on Jan. 14, 2023, 11:08 a.m.