# Idun
![Image of Idum](Idun.jpg)

A small CLI Tool to clean Backups from different Sources. Based on Rules Idun delete Backup files that are older but keep 1 per hour, per day, per weak or month.

## Buckets
Based on the age of a Backup the Backups will be sorted in one Bucket and based on the Rules of that Bucket will be deleted or keep the Backup.

### Unlimit Bucket (config per Hour)
Keep every Backup

You can configure that for the first X Hour of a Backup livetime. The number of hours is the **minimum** Hours Idun keep the Backups

### Hourly Bucket (config per Hour)
Will keep one Backup per Hour. One Hour is from Min 0 to Min 59, it will keep the olders Backup. If you make Backups at XX:00, XX:15, XX:30 and XX:45 it will keep the Backup at XX:45.

### Daily Backup (config per Day)
Will keep one Backup per Day. One Day is from 00:00:00 UTC to 23:59:59, it also will keep the olders Backup, tha backup closed to 23:59:59 will stay, all newer Backup at that day will be removed.

### Weekly Backup (config per Month)buc

### Monthly Backups (config per Month)

### Delete All
Delete all Backups in this Bucket, used at the end to remove all really old (based on the rules) backups

## Backends

### Locale Filesystem

Config parameter:

* path: Path to the folder on the Filesystem

### SFTP

issues: 

* Currenlty just with username/password
* untestet

Config parameter:

* path: Path to the folder on the Filesystem
* username: Username
* password: Password 
* addr: Server and Port (server:port)

### S3

issues:

* untestet

Config Parameter:

* prefix: Path/S3 Prefix to the Backups
* keyid: API Key Id
* secret: API Key Secret
* bucket: Name of the bucket
* endpoint: Endpoint
* region: Region


## Config

```
---
timezone: Europe/Berlin
jobs:
  - name: abc
    driver: LocaleFileSystem
    buckets:
      daily: 3
      monthly: 12
      hourly: 130
    config:
      path: /tmp/idun-test
  - name: abc2
    driver: LocaleFileSystem
    buckets:
      hourly: 12
    config:
      path: /tmp/idun-test
  - name: name
    driver: sftp
    buckets:
      monthly: 12
      weekly: 3
      daily: 3
      hourly: 24
      unlimit: 0
    config:
      path: /backup
      username: USERNAME
      password: PASSWORD
      addr: SERVER:PORT
  - name: git
    driver: s3
    config:
      prefix: git.keks.cloud/forgejo
      keyid: KEY
      secret: SECRET
      bucket: BUCKET
      endpoint: https://s3.eu-central-003.backblazeb2.com
      region: eu-central-003
    buckets:
      monthly: 12
      weekly: 3
      daily: 3
      hourly: 24
      unlimit: 0

```

## Usage 

### Show Plan
You can see the Plan to check if the config is what you are expected.

```
idun plan -job abc2   
```

The job argument is optional and can be used to show just the plan of on job based on the "name" in the config.

### Dry-Run
Show all fieles 
```
idun dry-run -job abc2   
```

The job argument is optional and can be used to show just the plan of on job based on the "name" in the config.

### Execute

Execute the deletion, will ask before deleting the files

```
idun execute -job abc2   
```

The job argument is optional and can be used to show just the plan of on job based on the "name" in the config.

### Cron run

Execute the deletion, **without** ask before deleting the files

```
idun execute -job abc2  -cron
```

The job argument is optional and can be used to show just the plan of on job based on the "name" in the config.


## FAQ
### Why minimum Hour/Day/Month
If you configure to keep one backup per hour for 12 hours Idun will make sure there will be hourly backups for at least 12 hours. But based on the rules of the next Buckets, which is per Day from 00:00:00 UTC to 23:59:59 UTC there may be a gap between the end hour of the "Hourly Bucket" and the beginn of the "Daily Bucket", in this case Iduna will not delete the Backup files. So ther will be up to 35 Hours Hourly Backups.
