User Tools

Site Tools


bash:backup_files_and_directories

BASH - Backup files and directories

Backup each file or directory that have been modified within the last 24 hour.

#!/bin/bash
 
BACKUPFILE=backup-$(date +%m-%d-%Y)
archive=${1:-$BACKUPFILE}
 
find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar"
echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."
exit 0

NOTE: It will print the names of the files and directories after the backup process is successful.

bash/backup_files_and_directories.txt · Last modified: 2021/01/09 13:48 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki