2
I have a productive environment for which I upload html, css etc. However, every time I upload a file I must first make a backup of existing occurrences.
I’m trying to build a script that does the following:
- Read the directory of upload and search in production if that file exists, if yes make a backup
- Copy the files to production and generate a list (txt) of the copied files
- If backup is required, I need the script to remove everything that was copied (to remove new elements if they exist) and copy back the backup files
However, I’m pretty lost since shell script is not my strong suit. Would anyone have any idea how to produce this script?
I currently have this code snippet:
#!/bin/bash
if [ ! $1 ]
then
echo "Informe o nome do diretorio de upload"
exit 0
fi
DirUpload=/home/upload/$1
DirProducao=/home/producao
cd $DirUpload
find . | sed 's/\.\///g' > upload.txt
for i in `cat $DirUpload/upload.txt`
do
if [ -d $DirProducao/$i ]
then
echo "Diretorio: ${i}"
elif [ -f $DirProducao/$i ]
then
echo "arquivo: ${i}"
else
echo "nao encontrado ${DirProducao}/${i}"
fi
done
For now I am using the above script to generate a txt with the list to be loaded, based on it I am checking what is currently in production to be able to copy to the backup
The upload directory is already production ?
– Roknauta
upload is the directory that contains the files to be loaded for production.
– Fábio Jânio
The first part I did quietly, maybe I finish the rest later.
– Roknauta