Blog

Creating a Backup Script to Store your Files on a NAS, another Device, or Directory.

This is a basic instructional script for backing up files with Robocopy onto my local NAS(Network Attached storage). Before proceeding, You should have enough general experience of folder navigation creation and Powershell enough to understand what this script does and doesn't do for you. For reasons being, especially when being security conscious, I tend to lean on not relying on apps and other toolsets to do the same things. A clean and focused environment means you can easily keep track of the scope of your work while still being able to have a good night's sleep knowing some app or other piece of software didn't leak your work or information without you aware of it. Backup tools are powerful, but only by your responsible use of it.

This scenario is for a local computer that I generally access all the time and very simply want to ensure my NAS has a second copy of files for when I humanly mess up. The NAS I have will take a snapshot of the share daily, an immutable snapshot, and then that snapshot is sent via rsync to an external backup in read-only and encrypted(That framework completes an entire triple redundancy for solo work whether it's programming, webdesign, artwork, CAD work and etc). I left the details out of this process intentionally and won't go over the nuances of Powershell Set-ExecutionPolicy (an important security Framework for Windows script safety) so we can focus on only the first universal stage of backing up files in Windows.

We are going to be running this script at startup/logon and executing it to backup only modified files to the destination we specify in the script. The first complete backup will take longer depending on the file sizes and amount.

IMPORTANT: Before running this script, we must change the execution policy in PowerShell from its default state. Run PowerShell as Administrator, then run the following entry:


Set-ExecutionPolicy RemoteSigned

You will be warned with "Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170". Which in our use case is for one personal computer that is not an enterprise environment. We are setting this because A) We want to run local scripts and B) It Doesn't require digital signatures on scripts that are written on the local computer and not downloaded from the internet. So, select A as Yes to all and that's it.

Let's now get our good ole' Notepad open and copy and paste this script in. Replace "C:\FOLDER_WITH_FILES_TO_BACKUP\" with the folder you want to backup, and "B:\OUR_BACKUP\DESTINATION" with the folder you want to back up to. Save this file to a memorable location like a new folder named scripts in your documents folder or C:/ directory.


# Define the source and destination paths(remember to edit these for your directories)
$sourcePath = "C:\FOLDER_WITH_FILES_TO_BACKUP\"
$destinationPath = "B:\OUR_BACKUP\DESTINATION"

# Check if the destination directory exists; if not, create it if (!(Test-Path -Path $destinationPath)) { New-Item -ItemType Directory -Path $destinationPath -Force }

# Perform backup, copying only new and modified files Robocopy $sourcePath $destinationPath /MIR /Z /XA:H /XD "System Volume Information" /R:3 /W:5

# Log the backup completion time $logPath = "$destinationPath\backup_log.txt" $timeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" Add-Content -Path $logPath -Value "Backup completed on $timeStamp"

Backup Command Robocopy is used to copy files with the following flags:

  • /MIR: Mirror the source and destination folders (will also delete files in the destination that are no longer in the source).
  • /Z: Enables restartable mode, allowing the transfer to resume if interrupted.
  • /XA:H: Excludes hidden files.
  • /XD "System Volume Information": Excludes the system volume information folder.
  • /R:3 and /W:5: Limits the retry count to 3 and sets a 5-second wait between retries.
  • Now to get that script running on startup. Let's open Task Scheduler and start by creating a basic task and ensure to add the script's directory as the argument as indicated in the last image.

    Post image
    Post image
    Post image
    Post image
    Post image

    And that's it! Now you have a templated script to back up additional directories later. I recommend naming the scripts as the directory/folder you want to backup as separate scripts so can refer back to them easily.

    Posted on: October 14, 2024, 3:03 pm

    Installing WSL 2024 - An Easy path into the Linux Wonderland

    Guide on Installing WSL2 Virtualization on Windows 10 version 2004 and higher (Build 19041 and higher) and Windows 11 - As of 2024

    Post image

    Perquisites:

  • Windows 10 or Windows 11
  • I recommend expanding your DDR/RAM/Memory to more than the 4Gb minimum (Though not required, and depending on your OS Type and updates installed it may require more, or you more than likely have enough)
  • Advanced Network Features may require Windows 11 22H2
  • Getting WSL2 installed on Windows is fairly straightforward now. Once you've taken your BIOS settings for a spin and tinkered enough. So, I'll just list the instructions here to keep going.

    1) Enable Virtualization for your CPU type

    Intel:

  • VT-x (Virtualization Technology) - also known as VanderPool
  • VT-d (Virtualization Technology for Directed I/O)
  • EPT (Extended Page Tables)
  • Arm:
  • ARMv7-A/ARMv8-A Virtualization Extensions (VE)
  • AMD:
  • AMD-V or SVM
  • 2) Install WSL from the Windows Feature Utility. A simple search in your windows start menu will list it under the keyword Windows Feature Utility. If not, press the WindowsKey+R keys for the "run" utility, type in "optionalfeatures", and press enter.

    Post image

    3) Restart your computer. Run Powershell as Administrator and type:
    
    	   wsl --update
    wsl --set-default-version 2
               
    4) Use either microsoft store or Powershell to display distributions and then install a Distribution of your choice.
    
    	   wsl --list -online
    wsl --install -d [Distribution name I.e. Ubuntu LTS]
               

    Congratulations!!! You now have a light Linux container of your choosing to use on Windows. A great introduction into a world of powerful tools once learned. I'll help with getting started on the important things to understand when using it in a later post. For now, tinker about! And I'll be back soon!

    Posted on: October 10, 2024, 1:26 am

    Image, Code, Paragraph Formatting Feature - Test Post

    Post image All Hail this test post. Post image

    Post image

    Sample Paragraph:

    Example 1: Benefits of Regular Exercise

    Regular exercise offers numerous benefits, both physically and mentally. Engaging in physical activities like jogging, swimming, or cycling helps improve cardiovascular health, strengthen muscles, and enhance flexibility. Exercise also plays a crucial role in weight management and reducing the risk of chronic diseases such as diabetes and hypertension. Moreover, regular physical activity is known to boost mental health by alleviating symptoms of depression and anxiety, promoting better sleep, and enhancing overall mood. By making exercise a part of your daily routine, you can significantly improve your quality of life and longevity.

    Example 2: Importance of Time Management

    Effective time management is essential for achieving success and maintaining a balanced life. By prioritizing tasks and setting clear goals, individuals can maximize productivity and reduce stress. Time management involves creating schedules, setting deadlines, and avoiding procrastination. It also requires the ability to delegate tasks when necessary and to focus on one task at a time. Proper time management not only helps in completing tasks efficiently but also allows for more free time to relax and pursue personal interests. Developing good time management skills is key to achieving both professional and personal goals.

    Sample Code Blocks:

    
    def load_pngs(self):         
       file_paths = filedialog.askopenfilenames(filetypes=[("PNG files", "*.png")])         
       if file_paths:             
          self.png_files.extend(file_paths)             
          self.update_preview_list()             
          self.show_preview()             
          self.update_preview_canvas_size()
    
    
    function getSeason(latitude) {
                const now = new Date();
                const month = now.getUTCMonth() + 1; // Months are zero-based
                let hemisphere = latitude >= 0 ? "northern" : "southern";
                let season;
    
    Posted on: October 7, 2024, 2:43 am