Commit 9257d5e1 authored by OskarStenberg's avatar OskarStenberg
Browse files

Updated backup script to patch images and env-files as well

parent 785d7d31
......@@ -135,6 +135,11 @@ if ! [ -d "$destinationDir/$lastBackup/patches" ]; then
mkdir "$destinationDir/$lastBackup/patches"
fi
#If there are no current file folders, create a folder for them
if ! [ -d "$destinationDir/$lastBackup/patches/files" ]; then
mkdir "$destinationDir/$lastBackup/patches/files"
fi
#Check and copy all files (images, .env) that are either new or changed.
cd new
files=$(find ".$snipeitDirectory" -type f)
......@@ -143,11 +148,26 @@ echo "$files"
echo "Trying to copy:"
while IFS= read -r file; do
if ! [ -f "$destinationDir/$lastBackup/$(echo $file | cut -c 3-)" ] || [ "$destinationDir/$lastBackup/$(echo $file | cut -c 3-)" -ot "$file" ]; then
if ! [ -f "$destinationDir/$lastBackup/$(echo $file | cut -c 3-)" ]; then
cp -u --parents "$file" "$destinationDir/$lastBackup/"
echo "Copied $file $destinationDir/$lastBackup/$(echo $file | cut -c 3-)"
else
echo "File already exists: $destinationDir/$lastBackup/$(echo $file | cut -c 3-)"
#Om filen redan finns, kolla om den finns i en nyare version på disken. Om den är nyare, kolla om den redan patchats.
if [ "$destinationDir/$lastBackup/$(echo $file | cut -c 3-)" -ot "$file" ]; then
lastFilePatch=$(ls -lt "$destinationDir/$lastBackup/patches/files" | head -2 | tail -1 | awk '{print $9}')
if [ "$destinationDir/$lastBackup/patches/files/$lastFilePatch/$(echo $file | cut -c 3-)" -ot "$file" ]; then
#If there are no current file folders for this backup, create a folder for them
if ! [ -d "$destinationDir/$lastBackup/patches/files/$now" ]; then
mkdir "$destinationDir/$lastBackup/patches/files/$now"
fi
cp --parents "$file" "$destinationDir/$lastBackup/patches/files/$now/"
echo "Copied $file $destinationDir/$lastBackup/patches/files/$now/$(echo $file | cut -c 3-)"
else
echo "File is already patched: $destinationDir/$lastBackup/patches/files/$lastFilePatch/$(echo $file | cut -c 3-)"
fi
else
echo "File already exists $destinationDir/$lastBackup/$(echo $file | cut -c 3-)"
fi
fi
done <<< "$files"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment