From cef5d509183882f98f56cb914a07fafca31a7a80 Mon Sep 17 00:00:00 2001 From: m5r Date: Sat, 18 Sep 2021 05:30:43 +0800 Subject: [PATCH] pad every number in backup file name --- db/backup.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/db/backup.ts b/db/backup.ts index 7b267d1..f473831 100644 --- a/db/backup.ts +++ b/db/backup.ts @@ -81,14 +81,18 @@ export default async function backup(schedule: "daily" | "weekly" | "monthly") { }); } +function pad(number: number) { + return number.toString().padStart(2, "0"); +} + function getFileName(database: string) { const now = new Date(); const year = now.getUTCFullYear(); - const month = (now.getUTCMonth() + 1).toString().padStart(2, "0"); - const day = now.getUTCDate(); - const hours = now.getUTCHours(); - const minutes = now.getUTCMinutes(); - const seconds = now.getUTCSeconds(); + const month = pad(now.getUTCMonth() + 1); + const day = pad(now.getUTCDate()); + const hours = pad(now.getUTCHours()); + const minutes = pad(now.getUTCMinutes()); + const seconds = pad(now.getUTCSeconds()); return `${database}-${year}-${month}-${day}_${hours}-${minutes}-${seconds}.sql.gz`; // 2021-09-15_16-00-02.sql.gz }