How to Backup a Directory/Folder in Bash

This post contains code that will enable you to automatically backup a directory and remove backups older than 3 weeks. The following Bash script is a cronjob directory backup script that takes two arguments: the folder to backup the output directory It will also automatically clean up any backups that are more than 3 weeks old. See below. The backup script #!/bin/bash -e outputtargz=$(basename "${2}" .tar.gz) tgtpath=$(dirname "${2}") output="${tgtpath}/${outputtargz}__$(date +%m-%d-%y_%H-%M)....

April 17, 2020 · 2 min · Charles M. Knox