I m trying to write a script that cleans up the specified directory by archiving and compressing (.tar.gz) all files older than the specified time.
And also, The archive must be accompanied by a script that allows you to roll back the changes made (i.e. unpack the archive and put the files back into directories).
#!/bin/bash
if [[ -n $1 && -n $2 ]]
then
dir=$1
daysold=$2
name=$(date '+%Y-%m-%d')'.tar'
cd $1
find -type f -mtime $daysold ! -name '*.tar.gz' -a -exec tar -uvf $name --remove-files {} \;
echo «Arcive was created successfully!»
gzip $name
echo «Compression complited successfully»
echo -e "#!/bin/bash\ntar -xvf $name.gz">$name+'_unzip.sh'
ug +x $name+'_unzip.sh'
echo "Script for unzip archive was created"
else
echo "Please, use the following pattern: archive_script.sh [~/path/to/directory] [N - files older than N days]"
fi
this is what I've got, but it doesn't work
./archievesolution.sh [/Users/glebpavlychev/Documents/ViberDownloads ] [10]
./archievesolution.sh: line 7: cd: [/Users/glebpavlychev/Documents/ViberDownloads: No such file or directory
find: illegal option -- t
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
«Archive was created successfully!»
gzip: can't stat: 2020-09-24.tar (2020-09-24.tar): No such file or directory
«Compression complited successfully»
./archievesolution.sh: line 13: ug: command not found
Script for unzip archive was created
(base) Glebs-MacBook-Pro:ViberDownloads glebpavlychev$