Académique Documents
Professionnel Documents
Culture Documents
R/POWERSHELL comments
Script Sharing Script to Compress and RoboCopy backup files to another this post was submitted on 12 Jan 2016
10
server, as well as clean up old files. (My first script - EVER) (self.PowerShell)
submitted 6 months ago * by admin_n00b
10
This is my first PS script that I have put together using pieces of scripts from all over the (92% upvoted)
place.
shortlink:
I have been searching for a script that would compress the Database backups every day,
and then copy them off the server for archiving. I also have this script files .zip's that are
older than seven days.
If you have any tips or criticism, I'm open to them all. I'll try to update the script as I get
suggestions, and will start the script as v1.0 and change this as I make changes here. remember me reset password login
The script has been written as modular as possible, and can easily be edited to not zip
the files, zip different files, not robocopy the files, or not delete old files.
Prerequisites
This script obviously requires PowerShell, but I am not aware if this works in all
versions. Confirmed to work in PowerShell 4. discuss this ad on reddit
This script also uses Robocopy, but I am not aware if this works in all versions.
Robocopy is bundled into Windows. My version will not give me a version number, Submit a new link
but it is the version bundled with Server 2012 R2.
This script requires the command line version of 7zip. Link to 7zip.org's download Submit a new text post
page.
The script assumes the following directory layout, which can be changed using the
PowerShell
"Variables" section at the start:
subscribe
Local Server Directories
17,662 readers
Backups folder: C:\Backups\
~40 users here now
Logs folder: C:\Backups\Logs\
ABOUT POWERSHELL
7zip executable: C:\7za\7za.exe
Windows PowerShell (POSH) is a command-line shell
and associated scripting language created by
Microsoft. Offering full access to COM, WMI and .NET,
Script POSH is a full-featured task automation framework
for distributed Microsoft platforms and solutions.
#################
## Zip backups ##
#################
discuss this ad on reddit
foreach ($file in $files)
{
$name = $file.name MODERATORS message the moderators
$directory = $file.DirectoryName
malice8691
7z a -tzip "$directory\$file.zip" "$directory\$name"
Davotronic5000
}
derekhans
############## about moderation team »
## Robocopy ##
############## < > discussions in /r/PowerShell X
· 1 comment
NET USE \\REMOTESERVER\Backups /user:REMOTESERVER\Robocopy pa55w0rd REQUEST: Need help taking Excel Workbook and
robocopy C:\Backups\ \\REMOTESERVER\Backups\ /E *.log *.bak *.zip /Z converting data to CSV
B /MIR $logparam
NET USE \\REMOTESERVER\Backups /D
#############
## Cleanup ##
#############
####################################################################
#########
## Note:
##
## Instead of using the 7zip program, you can use the native Windows
##
## compression, using:
##
##
##
## Add-Type -assembly "system.io.compression.filesystem"
##
## [io.compression.zipfile]::CreateFromDirectory($Source, $destina
tion) ##
##
##
## However, I prefer the 7zip programs versatility.
##
## More information at: http://www.dotnetperls.com/7-zip-examples
##
####################################################################
#########
4 comments share
all 4 comments
Thats a good point. The issue here, is that the two computers I created this for, are not part of a Domain.
Therefore, to access the share folder, Robocopy needed an account on the remote server (whichever way
around I put it).
However, I see your point. I'll play around with that and see if I can get that working within a Domain
environment.
permalink embed parent
Instead of using 7zip to do this, you could try to just call the native Windows compression:
[io.compression.zipfile]::CreateFromDirectory($Source, $destination)
permalink embed
I didn't realize that was an option. In all my searching, no one ever used that. Thanks.
However, I think I am going to keep 7zip in there, and add a footnote for this.
The 7zip program is far more versatile, allowing more compression types (.7z .tar .tar.gz etc.), as well as
having other parameters to control the compression, or adding files to a current archive of any type.
Side note: I am only using .zip because some machines on the network don't have ability to open .7z yet,
and .zip is handled natively by windows. But this will change in the future to a better compression
standard.
permalink embed parent
Use of this site constitutes acceptance of our User Agreement and Privacy Policy (updated). © 2016 reddit inc. All rights reserved.
REDDIT and the ALIEN Logo are registered trademarks of reddit inc.