This commit is contained in:
Frank Bischof 2023-06-08 09:28:26 +02:00
parent bc62d99054
commit 8374b03834
3 changed files with 114 additions and 73 deletions

View File

@ -1,8 +1,9 @@
# 7zip_to_netapp_v2.ps1
# 7zip_to_netapp.ps1
# Author: F. Bischof (info@meer-web.nl)
# Version 2.6.0
# Version 3.0.1
# Set global vars
$MAX_FOLDER_SIZE = "500GB"
$TIMESTAMP = Get-Date -Format "yyyyMMddHHmm"
$TARGET_FILENAME = "${TIMESTAMP}-archive.7z"
$CSVFILE = "C:\Scripts\movethis.csv"
@ -66,14 +67,38 @@ foreach ($SOURCE_ENTRY in $CSVFILE) {
WRITELOG "TARGET variable is empty! Please check the CSV file. Exiting..."
exit
}
WRITELOG "Archiving: $COUNTER - $SOURCE"
Write-Output "Archiving $SOURCE"
WRITELOG "Calculating folder size of $SOURCE"
Write-Output "Calculating folder size of $SOURCE"
$SOURCE_SIZE = (Get-ChildItem ${SOURCE} -Recurse| Measure-Object -Property Length -sum).Sum
$SOURCE_SIZE_FACTOR = [int]($SOURCE_SIZE / $MAX_FOLDER_SIZE)
if ($SOURCE_SIZE_FACTOR -ge 1) {
WRITELOG "$SOURCE is too big to compress using 7zip, switching to robocopy."
WRITELOG "Mirroring $SOURCE using robocopy"
robocopy /MIR ${SOURCE} ${TARGET}
$TARGET_SIZE = (Get-ChildItem ${TARGET} -Recurse| Measure-Object -Property Length -sum).Sum
if (${SOURCE_SIZE} -ne ${TARGET_SIZE}) {
WRITELOG "Source and destination sizes do not match!"; exit
} else {
WRITELOG "Source and destination sizes match"
}
WRITELOG "empty $SOURCE"
mkdir empty
robocopy /MIR empty ${SOURCE}
WRITELOG "Rename $SOURCE to "
$TEMPFOLDER_DONE = ${SOURCE} + "_is_archived_by_solvinity"
Rename-Item ${SOURCE} ${TEMPFOLDER_DONE}
WRITELOG "Temp quit on ${SOURCE}"
exit
} else {
# Create stagefolders which give the state of the source folder
Write-Output "Creating stage folder"
$TEMPFOLDER_RUNNING = ${SOURCE} + "_being_archived_by_solvinity"
$TEMPFOLDER_DONE = ${SOURCE} + "_is_archived_by_solvinity"
$TEMPFOLDER_FAILED = ${SOURCE} + "_archived_failed_by_solvinity"
$TEMPFOLDER_RUNNING = ${SOURCE} + "_being_archived"
$TEMPFOLDER_DONE = ${SOURCE} + "_is_archived"
$TEMPFOLDER_FAILED = ${SOURCE} + "_archived_failed"
WRITELOG "Creating stage folder $TEMPFOLDER_RUNNING"
if (!(test-path $TEMPFOLDER_RUNNING)){
New-Item -ItemType Directory $TEMPFOLDER_RUNNING
@ -144,4 +169,5 @@ foreach ($SOURCE_ENTRY in $CSVFILE) {
}
}
}
}
WRITELOG "=========================== Archiving ended ==========================="

View File

@ -1,3 +1,6 @@
## 3.0.1
- Added a $MAX_FOLDER_SIZE where if reached it switches to robocopy instead.
## 2.6.0
- Bugfixed CSVFile modification

View File

@ -3,8 +3,20 @@
This script is used for archiving major data.
## Requirements
The script only needs to know where to find the CSV file which needs to be loaded.
The script needs to know where to find the CSV file which needs to be loaded.
This CSV path can be set in the global vars part of the script.
- 7zip needs to be installed
- robocopy needs to be installed
## Configuration
$MAX_FOLDER_SIZE = Max folder size to zip, otherwise switch to robocopy.
$TIMESTAMP = Timeformat to use for the logfile
$TARGET_FILENAME = Target archive name
$CSVFILE = Source CSV file
$LOGFILE = Log file
$TEMPFOLDER_RUNNING = Source folder name for when archive is running
$TEMPFOLDER_DONE = Source folder name for when archive is done
$TEMPFOLDER_FAILED = Source folder name for when archive is failed
### CSV template
Create a CSV file containing the following setup:
@ -22,6 +34,6 @@ C:\temp\source_folder,D:\archive\target_folder
```
## Run script
> .\7zip_to_netapp_v2.ps1
> .\7zip_to_netapp.ps1
Just sit back and relax...