Add backup file ignore list.

This commit is contained in:
Logan Gorence 2021-12-28 09:40:44 +00:00
parent e681df1e65
commit 06eda8932a
No known key found for this signature in database
GPG Key ID: 9743CEF10935949A
3 changed files with 13 additions and 1 deletions

View File

@ -14,8 +14,10 @@ import java.io.BufferedOutputStream
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.Instant
import java.util.concurrent.atomic.AtomicBoolean
import java.util.zip.ZipEntry
@ -119,8 +121,10 @@ class BackupCommand(
}
private fun addDirectoryToZip(zipStream: ZipOutputStream, directoryPath: Path) {
val matchers = config.ignore.map { FileSystems.getDefault().getPathMatcher("glob:$it") }
val paths = Files.walk(directoryPath)
.filter { path: Path? -> Files.isRegularFile(path) }
.filter { path: Path -> Files.isRegularFile(path) }
.filter { path -> !matchers.any { it.matches(Paths.get(path.normalize().toString())) } }
.toList()
val buffer = ByteArray(1024)
val backupsPath = backupsPath.toRealPath()

View File

@ -5,6 +5,9 @@ import kotlinx.serialization.Serializable
@Serializable
data class BackupConfig(
val schedule: ScheduleConfig = ScheduleConfig(),
val ignore: List<String> = listOf(
"plugins/dynmap/web/**"
),
val s3: S3Config = S3Config(),
)

View File

@ -10,6 +10,11 @@ schedule:
# "0 3 ? * SUN" -> every Sunday at 3 AM
cron: ""
# List of file patterns to ignore and ignore in the backup.
ignore:
# Dynmap web output.
- "plugins/dynmap/web/**"
# Configuration of S3 service to upload back-ups to.
s3:
# The access key ID from your S3-compliant storage provider.