pad every number in backup file name

This commit is contained in:
m5r 2021-09-18 05:30:43 +08:00
parent b7bb5c1c33
commit cef5d50918

View File

@ -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
}