I create backup using rsync with the following two scripts:
Script 1:
#!/bin/bash
rsync --dry-run --stats -ab --human-readable --inplace --delete-delay --debug=NONE --log-file=/media/blueray/UltrastarDaily/rsync-WDPurple.log --backup-dir=purple_rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --exclude='lost+found' --exclude='.Trash-1000' /media/blueray/WDPurple /media/blueray/UltrastarDaily | sed -e '1,4d;6d;8,15d'
echo -e "\nDo you want to continue?"
while true; do
case $yn in
[Yy]* ) rsync --info=PROGRESS2,BACKUP,DEL -ab --human-readable --inplace --delete-delay --debug=NONE --log-file=/media/blueray/UltrastarDaily/rsync-WDPurple.log --backup-dir=purple_rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --exclude='lost+found' --exclude='.Trash-1000' /media/blueray/WDPurple /media/blueray/UltrastarDaily; break;;
[Nn]* ) exit;;
* ) read -p "Please answer yes or no: " yn;;
esac
done
Script 2:
#!/bin/bash
rsync --dry-run --stats -ab --human-readable --inplace --delete-delay --debug=NONE --log-file=/media/blueray/UltrastarDaily/rsync-WDRed.log --backup-dir=red_rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --exclude='lost+found' --exclude='.Trash-1000' /media/blueray/WDRed /media/blueray/UltrastarDaily | sed -e '1,4d;6d;8,15d'
echo -e "\nDo you want to continue?"
while true; do
case $yn in
[Yy]* ) rsync --info=PROGRESS2,BACKUP,DEL -ab --human-readable --inplace --delete-delay --debug=NONE --log-file=/media/blueray/UltrastarDaily/rsync-WDRed.log --backup-dir=red_rsync_bak.$(date +"%d-%m-%y_%I-%M-%S%P") --log-file-format='%t %f %o %M' --exclude='lost+found' --exclude='.Trash-1000' /media/blueray/WDRed /media/blueray/UltrastarDaily; break;;
[Nn]* ) exit;;
* ) read -p "Please answer yes or no: " yn;;
esac
done
The output looks like:
UltrastarDaily% tree -L 1
.
├── lost+found
├── purple_rsync_bak.06-02-21_06-38-44am
├── purple_rsync_bak.06-02-21_07-41-32pm
├── purple_rsync_bak.07-02-21_08-02-51am
├── purple_rsync_bak.07-02-21_08-17-26am
├── purple_rsync_bak.08-02-21_02-00-06am
├── red_rsync_bak.01-02-21_06-11-39pm
├── red_rsync_bak.06-02-21_06-16-58am
├── red_rsync_bak.06-02-21_06-23-24am
├── red_rsync_bak.06-02-21_06-26-58am
├── red_rsync_bak.06-02-21_06-27-30am
├── red_rsync_bak.06-02-21_06-31-36am
├── red_rsync_bak.06-02-21_06-33-14am
├── red_rsync_bak.06-02-21_06-34-04am
├── red_rsync_bak.06-02-21_06-34-52am
├── red_rsync_bak.06-02-21_06-35-22am
├── red_rsync_bak.06-02-21_06-41-48am
├── red_rsync_bak.06-02-21_07-39-41pm
├── red_rsync_bak.07-02-21_08-01-14am
├── red_rsync_bak.07-02-21_08-17-41am
├── red_rsync_bak.07-02-21_08-38-52am
├── red_rsync_bak.08-02-21_01-56-43am
├── red_rsync_bak.27-01-21_06-13-39pm
├── red_rsync_bak.28-01-21_02-22-31pm
├── red_rsync_bak.30-01-21_12-48-03am
├── rsync-WDPurple.log
├── rsync-WDRed.log
├── WDPurple
└── WDRed
27 directories, 2 files
I want to delete older purple_rsync_bak
and red_rsync_bak
directories if sufficient space is not available to make the current backup (by running Script 1
or Script 2
).
How can I do that?
..._rsync_bak
files? – Ahmad Ismail Feb 07 '21 at 19:32