====== bash - Backupscript ====== #!/bin/bash datapath=/var/www/doc backuppath=/var/backup/dokuwiki/ tar -czf $backuppath"doc_"$(date '+%Y%m%d').tar.gz $datapath filecount=$(ls -1 $backuppath | wc -l) if [ $filecount -gt 5 ]; then rm $(ls -td $backuppath/* | tail -$(expr $filecount - 5)) fi exit 0 Wichtig: * datapath -> Ohne abschließendes / * backuppath -> Mit abschließendem / Das Script erzeugt aus einem Dateipfad ein gzip-Archiv und löscht alle älteren Archive, außer den aktuellsten fünf Versionen. ===== Quellen ===== [[https://www.rapidtables.com/code/linux/ls/ls-full-path.html|ls voller Pfad]], [[https://tecadmin.net/tutorial/bash-scripting/bash-if-else-statement/|bash-Scripting]], [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html#toc6|bash-Scripting]], [[https://unix.stackexchange.com/questions/242496/bash-script-to-remove-the-oldest-file-from-from-a-folder|älteste Datei löschen]], [[https://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/|Rechnen in bash]], [[https://stackoverflow.com/questions/6749128/store-output-of-sed-into-a-variable|Variablenzuordnung in bash]], [[https://www.computerhope.com/issues/ch001326.htm|Dateien zählen in bash]] {{tag>[bash shell Script backup]}}