Automate System Backup Tasks with PowerShell
Managing server backups can often be a tedious chore, especially when handling multiple systems. Streamlining this process with automation can save time and reduce human error. In this post, we will introduce a PowerShell script that can help you automate your backup tasks efficiently. Our script not only creates a backup of specified directories but also archives them for easier storage and transport.
Moreover, if you are looking for a comprehensive solution to manage and automate various server tasks, consider using our software, ServerEngine. It provides a seamless user experience and robust features tailored to enhance your IT infrastructure’s performance and reliability.
Below is the script, which allows you to select directories for backup and compress them into a single archive file. It’s an excellent first step towards establishing a reliable backup strategy.
# Define the directories to backup $sourceDirectories = @("C:\ImportantData", "D:\Projects") # Define the backup destination $backupDestination = "E:\Backups" # Get the current date to append to the backup file name $currentDate = Get-Date -Format "yyyyMMdd" # Loop through each directory and create a compressed backup foreach ($directory in $sourceDirectories) { # Get the name of the directory only $directoryName = Split-Path -Leaf -Path $directory # Define the path for the output zip file $zipFilePath = "$backupDestination\$directoryName-$currentDate.zip" # Compress the directory Compress-Archive -Path $directory -DestinationPath $zipFilePath -Force } Write-Output "Backup completed successfully."