StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
00001  
#1 Posted : Friday, June 14, 2024 4:02:32 PM(UTC)
00001

Rank: Member

Reputation:

Groups: Approved
Joined: 3/31/2024(UTC)
Posts: 12

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Explanation:
IMPORTANT: The code should be at the very beginning to avoid deleting your other timers.
backupDays: >1 (how often to perform a backup when starting StrokesPlus, in days)
backupDays: >1, backupTime: "00:00" the same, but based on time (if the time has passed, the difference will be visible, e.g., 1_date_time(+50m) from the time when the backup should have been made)
backupDays: 0, interval: "10s" (options: s-seconds, m-minutes, h-hours) if createNew: 1 is specified (creates a new file/folder)
IMPORTANT: For backupDays: 0 and interval, timers are overwritten each time, so if you opened StrokesPlus and applied the settings, the timers will be reset again (a new report will start from the time you apply)
For each timer, there is a 5-second delay before execution (you can change it to any value)

If you encounter an error (when there are too many folders/files):
No script engine is available; discarding script. Try again.
Increase the value.
Options > Script > Max Script Pool Size и Max Script Lock Attempts

Global Actions > Load/Unload > Load

Shortened the code to take up less space.
Code:

const copyDirectory = (source, target) => { System.IO.Directory.CreateDirectory(target); System.IO.Directory.GetFileSystemEntries(source).forEach(entry => { const destEntry = System.IO.Path.Combine(target, System.IO.Path.GetFileName(entry)); System.IO.File.Exists(entry) ? System.IO.File.Copy(entry, destEntry, true) : System.IO.Directory.Exists(entry) && copyDirectory(entry, destEntry); }); };
const syncDirectory = (source, target) => { if (!System.IO.Directory.Exists(source)) return; System.IO.Directory.CreateDirectory(target); System.IO.Directory.GetFileSystemEntries(source).forEach(entry => { const destEntry = System.IO.Path.Combine(target, System.IO.Path.GetFileName(entry)); if (System.IO.File.Exists(entry)) { if (!System.IO.File.Exists(destEntry) || !System.IO.File.GetLastWriteTime(entry).Equals(System.IO.File.GetLastWriteTime(destEntry))) System.IO.File.Copy(entry, destEntry, true); } else if (System.IO.Directory.Exists(entry)) syncDirectory(entry, destEntry); }); System.IO.Directory.GetFileSystemEntries(target).forEach(entry => { const sourcePath = System.IO.Path.Combine(source, System.IO.Path.GetFileName(entry)); if (!System.IO.File.Exists(sourcePath) && !System.IO.Directory.Exists(sourcePath)) { if (System.IO.Directory.Exists(entry)) System.IO.Directory.Delete(entry, true); else if (System.IO.File.Exists(entry)) System.IO.File.Delete(entry); } }); };
const backup = (source, destDir, backupDays, backupTime, dateFormat = "yyyy-MM-dd", createNew = 0, interval = "") => { const fileName = System.IO.Path.GetFileName(source); const fileExtension = System.IO.Path.GetExtension(source); const fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(source); const separator = "_"; const lastBackupSuffix = "_last backup"; const currentDateTime = new Date(); const formattedDateTime = `${currentDateTime.getFullYear()}-${(currentDateTime.getMonth() + 1).toString().padStart(2, "0")}-${currentDateTime.getDate().toString().padStart(2, "0")}_${currentDateTime.getHours().toString().padStart(2, "0")}-${currentDateTime.getMinutes().toString().padStart(2, "0")}-${currentDateTime.getSeconds().toString().padStart(2, "0")}`; const destSubDir = backupDays ? `${fileNameWithoutExtension}${separator}${formatDate(new Date(), dateFormat)}${backupTime ? `_${backupTime.replace(":", "-")}${getTimeDifference(backupTime)}` : ''}${fileExtension}` : createNew ? `${fileNameWithoutExtension}${separator}${formattedDateTime}${fileExtension}` : `${fileNameWithoutExtension}${lastBackupSuffix}${fileExtension}`; const destFilePath = System.IO.Path.Combine(destDir, destSubDir); System.IO.Directory.CreateDirectory(destDir); if (shouldBackup(source, destDir, fileName, backupDays, separator, lastBackupSuffix, dateFormat, interval, createNew)) { if (System.IO.File.Exists(source)) System.IO.File.Copy(source, destFilePath, true); else if (System.IO.Directory.Exists(source)) syncDirectory(source, destFilePath); } };
const getFormattedDateTime = () => { const currentDateTime = new Date(); return `${currentDateTime.getFullYear()}_${(currentDateTime.getMonth() + 1).toString().padStart(2, "0")}_${currentDateTime.getDate().toString().padStart(2, "0")}_${currentDateTime.getHours().toString().padStart(2, "0")}-${currentDateTime.getMinutes().toString().padStart(2, "0")}-${currentDateTime.getSeconds().toString().padStart(2, "0")}`; };
const shouldBackup = (source, destDir, fileName, backupDays, separator, lastBackupSuffix, dateFormat, interval, createNew) => { const fileExtension = System.IO.Path.GetExtension(fileName); const fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName); const getBackupFiles = () => { const files = System.IO.Directory.GetFiles(destDir, `${fileNameWithoutExtension}${separator}*${fileExtension}`); return Array.from(files).map(file => { const match = file.match(new RegExp(`${fileNameWithoutExtension}${separator}(\\d{4}-\\d{2}-\\d{2})`)); return match ? { path: file, date: match[1] } : null; }).filter(Boolean); }; const getBackupDirs = () => { const dirs = System.IO.Directory.GetDirectories(destDir, `${fileNameWithoutExtension}${separator}*`); return Array.from(dirs).map(dir => { const match = dir.match(new RegExp(`${fileNameWithoutExtension}${separator}(\\d{4}-\\d{2}-\\d{2})`)); return match ? { path: dir, date: match[1] } : null; }).filter(Boolean); }; const todayDate = formatDate(new Date(), dateFormat); const backupFiles = getBackupFiles(); const backupDirs = getBackupDirs(); const hasTodayBackup = backupFiles.some(file => file.date === todayDate) || backupDirs.some(dir => dir.date === todayDate); if (System.IO.File.Exists(source)) { if (backupDays === 0 && interval) { return createNew ? true : !hasTodayBackup || !System.IO.File.GetLastWriteTime(source).Equals(System.IO.File.GetLastWriteTime(backupFiles.find(file => file.date === todayDate)?.path)); } else if (backupDays === 0) { return !hasTodayBackup || !System.IO.File.GetLastWriteTime(source).Equals(System.IO.File.GetLastWriteTime(backupFiles.find(file => file.date === todayDate)?.path)); } else { const dateCheckList = Array.from({ length: backupDays }, (_, i) => formatDate(new Date((new Date()).getTime() - (backupDays - i - 1) * 864e5), dateFormat)); return !dateCheckList.some(checkDate => backupFiles.some(file => file.date === checkDate)); } } else if (System.IO.Directory.Exists(source)) { if (backupDays === 0 && interval) { return createNew ? true : !hasTodayBackup || !System.IO.Directory.GetLastWriteTime(source).Equals(System.IO.Directory.GetLastWriteTime(backupDirs.find(dir => dir.date === todayDate)?.path)); } else if (backupDays === 0) { return !hasTodayBackup || !System.IO.Directory.GetLastWriteTime(source).Equals(System.IO.Directory.GetLastWriteTime(backupDirs.find(dir => dir.date === todayDate)?.path)); } else { const dateCheckList = Array.from({ length: backupDays }, (_, i) => formatDate(new Date((new Date()).getTime() - (backupDays - i - 1) * 864e5), dateFormat)); return !dateCheckList.some(checkDate => backupDirs.some(dir => dir.date === checkDate)); } } return false; };
const formatDate = (date, format) => format.replace(/yyyy|MM|dd/g, matched => ({ "yyyy": date.getFullYear(), "MM": ("0" + (date.getMonth() + 1)).slice(-2), "dd": ("0" + date.getDate()).slice(-2) })[matched]);
const parseInterval = interval => { const match = typeof interval === "string" && interval.match(/^(\d+)([hms])$/); return match ? parseInt(match[1]) * { h: 3600000, m: 60000, s: 1000 }[match[2]] : (typeof interval === "number" ? interval * 1000 : 0); };
const getLastBackupTime = (backupFolder, configFile) => { const fileName = System.IO.Path.GetFileName(configFile); const backupFolders = System.IO.Directory.GetDirectories(backupFolder, fileName + "*"); return backupFolders.length ? new Date(backupFolders.map(folder => System.IO.Directory.GetLastWriteTime(folder)).reduce((a, b) => a > b ? a : b)) : null; };
const startBackupProcess = (configFile, backupFolder, backupDays, backupTime, interval, createNew) => { const timerNameDaily = `BackupTimer_${configFile}_Daily_${backupDays}_${backupTime || 'NoTime'}`, timerNameInterval = `BackupTimer_${configFile}_Interval_${interval || ''}_CreateNew_${createNew}`, timerNameLastBackup = `BackupTimer_${configFile}_LastBackup`; sp.DeleteTimer(timerNameDaily); sp.DeleteTimer(timerNameInterval); sp.DeleteTimer(timerNameLastBackup); if (backupDays >= 1) { let initialDelay = 5000; if (backupTime) { const lastBackupTime = getLastBackupTime(backupFolder, configFile); const { nextBackupTime, timeDifference } = calculateNextBackupTime(lastBackupTime, backupDays, backupTime); initialDelay = Math.max(nextBackupTime.getTime() - Date.now(), 5000); } const backupCommand = `backup("${configFile.replace(/\\/g, "\\\\")}", "${backupFolder.replace(/\\/g, "\\\\")}", ${backupDays}, "${backupTime || ''}")`; sp.CreateTimer(timerNameDaily, initialDelay, 864e5, backupCommand); } else if (interval) { const intervalMs = parseInterval(interval); const backupCommand = `backup("${configFile.replace(/\\/g, "\\\\")}", "${backupFolder.replace(/\\/g, "\\\\")}", 0, "", "${interval}", ${createNew})`; sp.CreateTimer(timerNameInterval, 5000, intervalMs, backupCommand); } else if (backupDays === 0 && !interval) { const backupCommand = `backup("${configFile.replace(/\\/g, "\\\\")}", "${backupFolder.replace(/\\/g, "\\\\")}", 0, "", "", ${createNew})`; sp.CreateTimer(timerNameLastBackup, 5000, 864e5, backupCommand); } };
const calculateNextBackupTime = (lastBackupTime, backupDays, backupTime) => { if (!backupTime || !/^\d{1,2}:\d{2}$/.test(backupTime)) { return { nextBackupTime: new Date(Date.now() + backupDays * 864e5), timeDifference: '' }; } const [hours, minutes] = backupTime.split(':').map(Number); const now = new Date(); let nextBackupTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes); let timeDifference = ''; if (nextBackupTime < now) { timeDifference = getTimeDifference(backupTime); nextBackupTime = new Date(); } else if (lastBackupTime && lastBackupTime >= nextBackupTime) { nextBackupTime = new Date(nextBackupTime.getTime() + backupDays * 864e5); } return { nextBackupTime, timeDifference }; };
const getTimeDifference = backupTime => { const [hours, minutes] = backupTime.split(':').map(Number); const now = new Date(); const backupDateTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes); const diffInMinutes = Math.round((now - backupDateTime) / 60000); if (diffInMinutes > 0) { if (diffInMinutes >= 60) { const diffInHours = Math.floor(diffInMinutes / 60); return `(+${diffInHours}h)`; } else { return `(+${diffInMinutes}m)`; } } return ''; };
const stopAllBackupProcesses = () => sp.DeleteAllTimers();
const backupSettings = [
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2", backupDays: 1 },                      // Backup at Strokeplus startup , folder 1_(date)_(time) and will create a new folder every day
//{ configFile: "c:\\test\\1", backupFolder: "с:\\test2", backupDays: 1, backupTime: "00:00" }, // by time
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2\\", backupDays: 30 },                   // every 30 days
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2\\", backupDays: 0, interval: "10s" },                  // will create a folder 1_last backup and will update it every 10 seconds 
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2\\", backupDays: 0, interval: "10m", createNew: 1 },    // will create a new folder 1_(date)_(time) every 10 minutes
//{ configFile: "c:\\test\\1.txt", backupFolder: "c:\\test2", backupDays: 0 ,interval: "2h" },                 // will create a file 1_last backup.txt and will update it every 2 hours
//{ configFile: "c:\\test\\1.txt", backupFolder: "c:\\test2\\", backupDays: 0 ,interval: "59m", createNew: 1}, // will create a new file 1_(date)_(time).txt every 59 minutes
];
const startAllBackupProcesses=()=>{stopAllBackupProcesses();backupSettings.forEach(({configFile,backupFolder,backupDays,backupTime,interval,createNew})=>{startBackupProcess(configFile,backupFolder,backupDays,backupTime,interval,createNew);});};
startAllBackupProcesses();


The same thing in full length.
Code:

const copyDirectory = (source, target) => {
    System.IO.Directory.CreateDirectory(target);
    System.IO.Directory.GetFileSystemEntries(source).forEach(entry => {
        const destEntry = System.IO.Path.Combine(target, System.IO.Path.GetFileName(entry));
        System.IO.File.Exists(entry) ? System.IO.File.Copy(entry, destEntry, true) : System.IO.Directory.Exists(entry) && copyDirectory(entry, destEntry);
    });
};
const syncDirectory = (source, target) => {
    if (!System.IO.Directory.Exists(source)) return;
    System.IO.Directory.CreateDirectory(target);
    System.IO.Directory.GetFileSystemEntries(source).forEach(entry => {
        const destEntry = System.IO.Path.Combine(target, System.IO.Path.GetFileName(entry));
        if (System.IO.File.Exists(entry)) {
            if (!System.IO.File.Exists(destEntry) || !System.IO.File.GetLastWriteTime(entry).Equals(System.IO.File.GetLastWriteTime(destEntry)))
                System.IO.File.Copy(entry, destEntry, true);
        } else if (System.IO.Directory.Exists(entry))
            syncDirectory(entry, destEntry);
    });
    System.IO.Directory.GetFileSystemEntries(target).forEach(entry => {
        const sourcePath = System.IO.Path.Combine(source, System.IO.Path.GetFileName(entry));
        if (!System.IO.File.Exists(sourcePath) && !System.IO.Directory.Exists(sourcePath)) {
            if (System.IO.Directory.Exists(entry))
                System.IO.Directory.Delete(entry, true);
            else if (System.IO.File.Exists(entry))
                System.IO.File.Delete(entry);
        }
    });
};
const backup = (source, destDir, backupDays, backupTime, dateFormat = "yyyy-MM-dd", createNew = 0, interval = "") => {
    const fileName = System.IO.Path.GetFileName(source);
    const fileExtension = System.IO.Path.GetExtension(source);
    const fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(source);
    const separator = "_"; // can be changed to any
    const lastBackupSuffix = "_last backup"; // can be changed to any
    const currentDateTime = new Date();
    const formattedDateTime = `${currentDateTime.getFullYear()}-${(currentDateTime.getMonth() + 1).toString().padStart(2, "0")}-${currentDateTime.getDate().toString().padStart(2, "0")}_${currentDateTime.getHours().toString().padStart(2, "0")}-${currentDateTime.getMinutes().toString().padStart(2, "0")}-${currentDateTime.getSeconds().toString().padStart(2, "0")}`;
    const destSubDir = backupDays
        ? `${fileNameWithoutExtension}${separator}${formatDate(new Date(), dateFormat)}${backupTime ? `_${backupTime.replace(":", "-")}${getTimeDifference(backupTime)}` : ''}${fileExtension}`
        : createNew
            ? `${fileNameWithoutExtension}${separator}${formattedDateTime}${fileExtension}`
            : `${fileNameWithoutExtension}${lastBackupSuffix}${fileExtension}`;
    const destFilePath = System.IO.Path.Combine(destDir, destSubDir);
    System.IO.Directory.CreateDirectory(destDir);
    if (shouldBackup(source, destDir, fileName, backupDays, separator, lastBackupSuffix, dateFormat, interval, createNew)) {
        if (System.IO.File.Exists(source))
            System.IO.File.Copy(source, destFilePath, true);
        else if (System.IO.Directory.Exists(source))
            syncDirectory(source, destFilePath);
    }
};
function getFormattedDateTime() {
    const currentDateTime = new Date();
    return `${currentDateTime.getFullYear()}_${(currentDateTime.getMonth() + 1).toString().padStart(2, "0")}_${currentDateTime.getDate().toString().padStart(2, "0")}_${currentDateTime.getHours().toString().padStart(2, "0")}-${currentDateTime.getMinutes().toString().padStart(2, "0")}-${currentDateTime.getSeconds().toString().padStart(2, "0")}`;
}
const shouldBackup = (source, destDir, fileName, backupDays, separator, lastBackupSuffix, dateFormat, interval, createNew) => {
    const fileExtension = System.IO.Path.GetExtension(fileName);
    const fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);
    const getBackupFiles = () => {
        const files = System.IO.Directory.GetFiles(destDir, `${fileNameWithoutExtension}${separator}*${fileExtension}`);
        return Array.from(files).map(file => {
            const match = file.match(new RegExp(`${fileNameWithoutExtension}${separator}(\\d{4}-\\d{2}-\\d{2})`));
            return match ? { path: file, date: match[1] } : null;
        }).filter(Boolean);
    };
    const getBackupDirs = () => {
        const dirs = System.IO.Directory.GetDirectories(destDir, `${fileNameWithoutExtension}${separator}*`);
        return Array.from(dirs).map(dir => {
            const match = dir.match(new RegExp(`${fileNameWithoutExtension}${separator}(\\d{4}-\\d{2}-\\d{2})`));
            return match ? { path: dir, date: match[1] } : null;
        }).filter(Boolean);
    };
    const todayDate = formatDate(new Date(), dateFormat);
    const backupFiles = getBackupFiles();
    const backupDirs = getBackupDirs();
    const hasTodayBackup = backupFiles.some(file => file.date === todayDate) || backupDirs.some(dir => dir.date === todayDate);
    if (System.IO.File.Exists(source)) {
        if (backupDays === 0 && interval) {
            return createNew ? true : !hasTodayBackup || !System.IO.File.GetLastWriteTime(source).Equals(System.IO.File.GetLastWriteTime(backupFiles.find(file => file.date === todayDate)?.path));
        } else if (backupDays === 0) {
            return !hasTodayBackup || !System.IO.File.GetLastWriteTime(source).Equals(System.IO.File.GetLastWriteTime(backupFiles.find(file => file.date === todayDate)?.path));
        } else {
            const dateCheckList = Array.from({ length: backupDays }, (_, i) => formatDate(new Date((new Date()).getTime() - (backupDays - i - 1) * 864e5), dateFormat));
            return !dateCheckList.some(checkDate => backupFiles.some(file => file.date === checkDate));
        }
    } else if (System.IO.Directory.Exists(source)) {
        if (backupDays === 0 && interval) {
            return createNew ? true : !hasTodayBackup || !System.IO.Directory.GetLastWriteTime(source).Equals(System.IO.Directory.GetLastWriteTime(backupDirs.find(dir => dir.date === todayDate)?.path));
        } else if (backupDays === 0) {
            return !hasTodayBackup || !System.IO.Directory.GetLastWriteTime(source).Equals(System.IO.Directory.GetLastWriteTime(backupDirs.find(dir => dir.date === todayDate)?.path));
        } else {
            const dateCheckList = Array.from({ length: backupDays }, (_, i) => formatDate(new Date((new Date()).getTime() - (backupDays - i - 1) * 864e5), dateFormat));
            return !dateCheckList.some(checkDate => backupDirs.some(dir => dir.date === checkDate));
        }
    }
    return false;
};
const formatDate = (date, format) =>
    format.replace(/yyyy|MM|dd/g, matched => ({
        "yyyy": date.getFullYear(),
        "MM": ("0" + (date.getMonth() + 1)).slice(-2),
        "dd": ("0" + date.getDate()).slice(-2)
    })[matched]);
const parseInterval = interval => {
    const match = typeof interval === "string" && interval.match(/^(\d+)([hms])$/);
    return match ? parseInt(match[1]) * { h: 3600000, m: 60000, s: 1000 }[match[2]] : (typeof interval === "number" ? interval * 1000 : 0);
};
const getLastBackupTime = (backupFolder, configFile) => {
    const fileName = System.IO.Path.GetFileName(configFile);
    const backupFolders = System.IO.Directory.GetDirectories(backupFolder, fileName + "*");
    return backupFolders.length ? new Date(backupFolders.map(folder => System.IO.Directory.GetLastWriteTime(folder)).reduce((a, b) => a > b ? a : b)) : null;
};
const startBackupProcess = (configFile, backupFolder, backupDays, backupTime, interval, createNew) => {
    const timerNameDaily = `BackupTimer_${configFile}_Daily_${backupDays}_${backupTime || 'NoTime'}`;
    const timerNameInterval = `BackupTimer_${configFile}_Interval_${interval || ''}_CreateNew_${createNew}`;
    const timerNameLastBackup = `BackupTimer_${configFile}_LastBackup`;
    
    sp.DeleteTimer(timerNameDaily);
    sp.DeleteTimer(timerNameInterval);
    sp.DeleteTimer(timerNameLastBackup);
    
if (backupDays >= 1) {
        let initialDelay = 5000; // 5 seconds default
        
        if (backupTime) {
            const lastBackupTime = getLastBackupTime(backupFolder, configFile);
            const { nextBackupTime, timeDifference } = calculateNextBackupTime(lastBackupTime, backupDays, backupTime);
            initialDelay = Math.max(nextBackupTime.getTime() - Date.now(), 5000);
        }
        
        const backupCommand = `backup("${configFile.replace(/\\/g, "\\\\")}", "${backupFolder.replace(/\\/g, "\\\\")}", ${backupDays}, "${backupTime || ''}")`;
        sp.CreateTimer(timerNameDaily, initialDelay, 864e5, backupCommand);
    } else if (interval) {
        const intervalMs = parseInterval(interval);
        const backupCommand = `backup("${configFile.replace(/\\/g, "\\\\")}", "${backupFolder.replace(/\\/g, "\\\\")}", 0, "", "${interval}", ${createNew})`;
        sp.CreateTimer(timerNameInterval, 5000, intervalMs, backupCommand);
    } else if (backupDays === 0 && !interval) {
        const backupCommand = `backup("${configFile.replace(/\\/g, "\\\\")}", "${backupFolder.replace(/\\/g, "\\\\")}", 0, "", "", ${createNew})`;
        sp.CreateTimer(timerNameLastBackup, 5000, 864e5, backupCommand);
    }
};
const calculateNextBackupTime = (lastBackupTime, backupDays, backupTime) => {
    if (!backupTime || !/^\d{1,2}:\d{2}$/.test(backupTime)) {
        return { nextBackupTime: new Date(Date.now() + backupDays * 864e5), timeDifference: '' };
    }
    const [hours, minutes] = backupTime.split(':').map(Number);
    const now = new Date();
    let nextBackupTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
    let timeDifference = '';
    if (nextBackupTime < now) {
        timeDifference = getTimeDifference(backupTime);
        nextBackupTime = new Date(); // Set the current time for immediate backup
    } else if (lastBackupTime && lastBackupTime >= nextBackupTime) {
        nextBackupTime = new Date(nextBackupTime.getTime() + backupDays * 864e5);
    }
    return { nextBackupTime, timeDifference };
};
const getTimeDifference = backupTime => {
    const [hours, minutes] = backupTime.split(':').map(Number);
    const now = new Date();
    const backupDateTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
    const diffInMinutes = Math.round((now - backupDateTime) / 60000);
    if (diffInMinutes > 0) {
        if (diffInMinutes >= 60) {
            const diffInHours = Math.floor(diffInMinutes / 60);
            return `(+${diffInHours}h)`;
        } else {
            return `(+${diffInMinutes}m)`;
        }
    }
    return '';
};
const stopAllBackupProcesses = () => sp.DeleteAllTimers();
const backupSettings = [ 
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2", backupDays: 1 },                      // Backup at Strokeplus startup , folder 1_(date)_(time) and will create a new folder every day
//{ configFile: "c:\\test\\1", backupFolder: "с:\\test2", backupDays: 1, backupTime: "00:00" }, // by time
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2\\", backupDays: 30 },                   // every 30 days
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2\\", backupDays: 0, interval: "10s" },                  // will create a folder 1_last backup and will update it every 10 seconds 
//{ configFile: "c:\\test\\1", backupFolder: "c:\\test2\\", backupDays: 0, interval: "10m", createNew: 1 },    // will create a new folder 1_(date)_(time) every 10 minutes
//{ configFile: "c:\\test\\1.txt", backupFolder: "c:\\test2", backupDays: 0 ,interval: "2h" },                 // will create a file 1_last backup.txt and will update it every 2 hours
//{ configFile: "c:\\test\\1.txt", backupFolder: "c:\\test2\\", backupDays: 0 ,interval: "59m", createNew: 1}, // will create a new file 1_(date)_(time).txt every 59 minutes
];
const startAllBackupProcesses = () => {
    stopAllBackupProcesses();
    backupSettings.forEach(({ configFile, backupFolder, backupDays, backupTime, interval, createNew }) => {
        startBackupProcess(configFile, backupFolder, backupDays, backupTime, interval, createNew);
    });
};
startAllBackupProcesses();

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.