// Schedule: 0 0 */2 * * // Name: Scheduled Folder Backup // Description: Incrementally backup a folder to an external SSD every 2 days using rsync. import "@johnlindquist/kit" try { // 1. Prompt the user to select the source folder for backup const sourceFolder = await path({ hint: "Select folder to backup:", onlyDirs: true, }); if (!sourceFolder) { notify("Backup cancelled: Source folder not selected."); exit(); // Exit the script if no source folder is selected return; } // 2. Prompt the user to select the destination folder on the external SSD const destinationFolder = await path({ hint: "Select external SSD destination:", onlyDirs: true, }); if (!destinationFolder) { notify("Backup cancelled: Destination folder not selected."); exit(); // Exit if no destination folder is selected return; } // 3. Construct the rsync command for incremental backup // -avz: archive mode (recursive, preserves permissions, times, etc.), verbose, compress // --delete: delete extraneous files from destination dirs (files that no longer exist in source) // --progress: show progress during transfer for better user feedback const command = `rsync -avz --delete --progress "${sourceFolder}/" "${destinationFolder}"`; // 4. Execute the rsync command await exec(command); // 5. Notify the user that the backup has completed successfully notify("Backup completed successfully!"); } catch (error) { // 6. Handle any errors that occur during the backup process console.error(`Backup failed: ${error}`); notify({ title: "Backup Failed!", body: "See logs for details.", icon: "error" // You might need to define or have a default 'error' icon }); }