Skip to content

gdsotirov/spsb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

SPSB

A Simple PowerShell Backup script for creation of timestamped backups of files and folders as Zip archives.

Abstract

The purpose of the script is to back up a whole folder or a single file from a Windows machine to a network share (Samba) as timestamped Zip archives. It's intended to be run regularly as a scheduled task or at system events like user log off or system shutdown.

Configuration

It's necessary to manually modify the variables at the beginning of the script to provide some real host and user names and passwords.

Setting up script execution with Task Scheduler

To setup the script for execution at specific time do the following:

  1. Go to Start Menu -> Run (or press Win Key + R).
  2. Type taskschd.msc and hit enter to open Task Scheduler.
  3. Go to Action -> Create Task...
  4. Enter task name (e.g. Backup) and description (e.g. Backup files and folders from this computer to a network share) on tab General in the dialog and choose Security options.
  5. Go to Triggers and add scheduling by clicking on New... button.
  6. Then go to Actions and click on New... button.
  7. Select Start a program in Action and select the script in Program/script.
  8. Eventually choose other options on Conditions and Settings tab.
  9. click on OK to save the task.

Setting up script execution with Local Group Policy Editor

To setup the script for execution at user log off do the following:

  1. Go to Start Menu -> Run (or press Win Key + R).
  2. Type gpedit.msc and hit enter to open Local Group Policy Editor.
  3. Go to User configuration -> Windows Settings -> Scripts (Logon/Logoff).
  4. Click on Logoff on the right and select PowerShell Scripts tab in the dialog.
  5. Click on Add... button, then select the script.

To setup the script for execution at system shutdown do the following:

  1. Go to Start Menu -> Run (or press Win Key + R).
  2. Type gpedit.msc and hit enter to open Local Group Policy Editor.
  3. Go to Computer configuration -> Windows Settings -> Scripts (Startup/Shutdown).
  4. Click on Shutdown on the right and select PowerShell Scripts tab in the dialog.
  5. Click on Add... button, then select the script.

Requirements

The script requires:

Known issues

The script is a work in progress although working well on several PCs for years already. These are the currently known issues:

  • the script would not run unless you enable a less restrictive execution policy (see About Execution Policies);
  • if file is being used by another process the backup fails with error "The process cannot access the file 'file' because it is being used by another process.", which could be avoided if the script is executed at user log off or system shutdown events, instead of scheduled;
  • if the network share is already accessed with different credentials then backup drive creation would fail, because in Windows "by design" and for security reasons "one server (uniquely identified by the given name) can only have one user authenticated to it at a given time" (see KB938120 for explanation and workarounds);
  • when archiving a single file with size over 300 MB the script may fail with the following error:
    Exception calling "CreateEntryFromFile" with "3" argument(s): "Exception of type 'System.OutOfMemoryException' was thrown."
    
    It was found on system running Windows 10 (32 bit) with just 4 GB RAM. On the same system archiving the same file with Send to → Compressed (zipped) folder works just fine. No known workaround at present.

About

A simple PowerShell backup script

Topics

Resources

License

Stars

Watchers

Forks