fbpx XOMedia

IT

Simple Data Protection for your Computer

Quick Summary: An elegant, easy to implement and lightning fast backup solution for on-site / off-site data replication.
  
Last updated: | Leave a comment

Overview

Data protection is one of the pillars of IT. It’s no fun losing days, weeks, months and years of work. Data loss is not a matter of if, but when. In this article we detail an elegant and basic data protection solution for your PC or Laptop.

Taking the time to setup a proper backup system is critical to avoid headaches that will cost you precious time and money later.

This solution has been adapted to Window, but can easily be tailored for Unix, Linux and BSD.

We will be presenting a basic data protection scheme following the 3-2-1 rule:

  • 3 – Keep 3 copies of your data: 1 primary and 2 backups.
  • 2 – Keep data on 2 different media types to protect against different types of hazards.
  • 1 – Store 1 copy offsite (e.g. outside your home, business or facility).

Summarizing:

Devices can fail at any time, without warning – and for various reasons. You can protect against this by following the 3-2-1 rule.

It’s strongly recommended to maintain an off-site backup to protect against fire or theft. This ensures you will not lose critical data even in worse case scenarios.

Benefits

Design Philosophy: When designing solutions, it’s important to separate design from implementation, keeping (hardware, OS / software) as agnostic as possible. Always follow best practices, while maintaining flexibility of being able to switch the underlying components to avoid vendor lock-in. In the sections that follow, we’ll present an agnostic solution implemented using freely available tools.

simpleBackups Benefits

  • Provides the ability to recover files that have been affected by hardware and software failures, viruses or humans.
  • Fast & Efficient:
    • Only replicates files that have changed since the last backup.
    • Optimized for slow networks and does not put to much wear on drives.
  • Easy to read console output to quickly spot errors.
  • Configure any number of internal, external or remote storage devices.
    Script can easily be adapted to backup data to cloud providers such as Amazon, Google, Microsoft or DropBox.
  • Automation & Manual execution methods.
  • Monitoring & Email reports (only) when there’s failures.

Storage

The following storage configuration adequately protects against planned and unplanned failures:

  • 1 NVMe drive: This is where the OS, applications and frequently accessed data resides.
  • The reason for this recommendation is two-fold: #1 The SSDs will provide high performance for the OS, demanding workloads and frequently accessed data you are working on. #2 while the hard drives will provide a lot of storage space to save your projects and other large files for backup.
  • 2 drives: This can be 2 internal SATA drives or 1 internal SATA / 1 external USB drive.
  • 1 offsite: This can be the 2nd USB external drive that can be shipped and attached to a remote (offsite) server. Or (preferred), data can replicated to an off-prem server or Cloud provider.

Dependencies

FastCopy

Download and install FastCopy:

A default installation will suffice.

Python

Download and install Python:

Install with the following options checked:

Use admin privileges when installing py.exe

Add python.exe to PATH

Select the ‘Install Now’ option.

Finally, verify the installation:

C:\Users\xomedia> py --version
Python 3.12.2

Script

Now to install and configure the script.

If possible, it’s best to write portable code – write once execute everywhere. For example:

simpleBackups.py is implemented in Python and can be easily adapted / extended to run on other platforms like: AIX, BSD, HP-UX, macOS and Solaris.

1) Just click the following button to download the script and then unzip:

2) Copy the script to a final location, for example: C:\Program Files\simpleBackups

3) Now open the Python script in your favorite editor to configure the following global variables:

# ------------------------------------------------------------------------------
# Globals:
# ------------------------------------------------------------------------------

# Destination drive(s) to back up to:
# NOTEs:
#    Can be a single letter, or a comma separated list of drives.
#    This can be overridden via the -d switch.
drives = "d"

# Windows user account the script is executed from:
user = "xomedia"

# Backup specification:
# NOTE: Can be a single path, or a comma separated list of paths to back up.
specifications = r"\Users\xomedia\Desktop"  # Use for testing
#specifications = r"\Users\xomedia\Desktop,\Users\xomedia\Downloads"  # Use for testing

# Enable email reporting?
email = True
# Mail configuration section (using SendGrid):
port = 587
smtp_server = "smtp.sendgrid.net"  # SMTP relay server
login = "apikey"  # Account login
password = "SG.************************************"  # Account password or API Key
message = MIMEMultipart()
sender_email = "[email protected]"  # Email sending account
receiver_email = "[email protected]"  # Email to receive reports
#message = MIMEMultipart("alternative")
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = "SimpleBackups:"

# ------------------------------------------------------------------------------

‘drives:’ Can be a single drive or comma separated list:

NOTE: We will be using the -d switch to specify the drive(s).

drives = "d,e"

The Windows user account the script will execute from:

Example: C:\Users\xomedia

user = "xomedia"

You can determine the logged in account via cmd:

Microsoft Windows [Version 10.0.22631.3296]
(c) Microsoft Corporation. All rights reserved.

C:\Users\xomedia> whoami
xomedia\xomedia

C:\Users\xomedia>

Optionally, you can configure email reporting. The script parses the backup logs and triggers an email alert if anything goes wrong. This option requires an SMTP relay server. If you do not have one, there are several free SMTP services covered in the next section.

email = True

4) Finally, test – execute the script with a -h to get usage:

C:\Users\xomedia> py C:\Program Files\simpleBackups\simpleBackups.py -h
usage: simpleBackups1.py [-h] [-d DRIVES]

$Id: simpleBackups.py v2.0 2024-Mar-27  $

options:
  -h, --help            show this help message and exit
  -d DRIVES, --drives DRIVES
                        Specify one or more destination drive letters: -d "d,e" or --drives "f"

C:\Users\xomedia>

Email Reporting

In order to use the email reporting option, you will need access to an SMTP relay server. If you do not have one, most SMTP relay providers offer a free pricing tier. Usually, there is a cap on the number of emails you can send daily / monthly – but this is usually plenty for system emails. Mailersend, for example, allows you to send up to 3,000 emails per month.

Here’s a collection of article reviews of some of the most popular services:

  • Kinsta: How to Use a Free SMTP Server for WordPress Emails (Including Gmail SMTP Server)
  • Email Vendor Selection: 10 Best Free SMTP Servers for Transactional Emails
  • Moosend: 11 Free SMTP Server Solutions For Marketers & Developers
  • EmailTooltester: The 10 Best Free SMTP Servers

Here’s setup instructions for two of the most popular free services:

Gmail [500/day limit]:

Instructions:

Mailmeteor: How To Set Up Your Gmail SMTP Settings

Kinsta: How to Use the Gmail SMTP Server to Send Emails for Free [Skip the WordPresss related instructions, follow: “2. Create Your Google App.]”

SendGrid [free (no credit card required) 100 emails/day forever]:

Instructions:

Kinsta: How to Configure SendGrid in WordPress to Send Emails

A shorter set of instructions to create the SendGrid API Key:

Gravity Forms: Generating Your SendGrid API Key

Groundhogg: SMTP: Connect to Sendgrid

Sample report:

Diagram 2

Execution

You can either execute the backups manually, or automate it with Task Scheduler – or both (recommended).

Configuring both allows you to execute backups job on a regular schedule and manually running a backup if a lot of data has changed. Manual execution also enables you to inspect the console output to make sure things are running smoothly.

Manual:

You can either configure a shortcut or execute the script from the CMD terminal manually.

Right-click on your Desktop or in an Explorer window: New > Shortcut and add the following line in the field labeled “Target:”

C:\Users\xomedia\AppData\Local\Programs\Python\Launcher\py.exe C:\storage1\storage-dev\scripts\Backups\simpleBackups\simpleBackups.py

Select ‘Run: Minimized’ if you do not want a terminal window to open.

Executing via the terminal:

C:\Users\xomedia> py C:\storage1\storage-dev\scripts\Backups\simpleBackups\simpleBackups.py

Backing up to Drive: d

Syncing: \Users\xomedia\Desktop
Dir / File count (c): 204
Dir / File count (d): 204
Result : (ErrFiles : 0 / ErrDirs : 0) at 2024/03/26 00:38:45

Syncing: \Users\xomedia\Downloads
Dir / File count (c): 9720
Dir / File count (d): 9720
Result : (ErrFiles : 0 / ErrDirs : 0) at 2024/03/26 00:38:45

Syncing: \storage
Dir / File count (c): 9720
Dir / File count (d): 9720
Result : (ErrFiles : 0 / ErrDirs : 0) at 2024/03/26 00:38:45

Automation:

Automating with Windows Task Manager is easy.

You can follow this quick guide to learn how to create a scheduled task:

How to create a new task using Windows Task Scheduler

Configure two tasks referencing the below screenshots – one task for each drive.

In reference to slide #3, add:

Program/script: C:\Users\xomedia\AppData\Local\Programs\Python\Launcher\py.exe

Add arguments: C:\storage1\storage-dev\scripts\Backups\FastCopy\simpleBackups.py -d d

NOTE: Use -d <drive letter> to specify the destination drive(s) to back up to.


Test thoroughly!

Limitations

As mentioned earlier, this solution is only for basic data protection. It will not protect against all types of data loss, such as unsuspected corruption being introduced into files after several generations of backups and revisions have since occurred.

In most cases, by the time these types of errors are detected / noticed – it’s already too late to recover (because you can’t go back and replay time). Using backup rotation schemes would be pointless because the most recent generations will have the error. To protect data in this scenario, you would need to have at least one of the older generations that have a file version that does not contain the error.

Maintaining a history of file changes enables point-in-time recovery. If a file ever becomes corrupted, it can be spotted and reverted back to a point-in-time prior to the corruption.

A popular option for source code, configuration and documentation files is to use a Source Control Management solution (e.g., git). This enables you to have multiple backups and track changes / versions.

Summary

In this article we covered how to implement a basic backup solution for Windows.

We used a best practice approach that is redundant and takes a DRP (Disaster Recovery Plan) strategy into account.

This solution lacks a point-in-time recovery, which is out of scope for this article and may be covered in a future post.

A final note, simpleBackups is not a enterprise backup solution, and should not be used as a replacement for one.


Thanks for reading!

If you enjoyed this post, please share:  

XOMedia is a full-service IT solutions provider. Learn how your business can benefit from XOMedia's 30+ years of experience with our Consulting and Partnership services - all work is backed by our 100% guaranteed.



Back to Blog Home

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
To top