aboutsummaryrefslogtreecommitdiffstats
path: root/bin/crypted-backups
diff options
context:
space:
mode:
Diffstat (limited to 'bin/crypted-backups')
-rwxr-xr-xbin/crypted-backups27
1 files changed, 24 insertions, 3 deletions
diff --git a/bin/crypted-backups b/bin/crypted-backups
index 3019c7e..d96ad36 100755
--- a/bin/crypted-backups
+++ b/bin/crypted-backups
@@ -10,6 +10,7 @@ else
fi
user_mode=""
source_mode=""
+cleanup_mode=0
verbose=0
function notification_source_to_destination () {
@@ -53,6 +54,17 @@ function sanitize_pathname () {
fi
}
+function check_cleanup_settings () {
+ [ $verbose -gt 0 ] && echo "Checking cleanup settings."
+ if ![[ $cleanup_older_than =~ '^[0-9]+$' ]];then
+ echo "Error! \"cleanup_older_than\" is not an integer: $cleanup_older_than."
+ return 1
+ elif [ ${#cleanup_directory} -eq 0 ];then
+ echo "Error! \"cleanup_directory\" is not set!"
+ return 1
+ fi
+}
+
function check_gpg_set () {
[ $verbose -gt 0 ] && echo "Checking, if \"gpg_public_key\" is set."
if [ -z "$gpg_public_key" ];then
@@ -333,15 +345,22 @@ function set_user_mode () {
return 0
}
+function cleanup_backup () {
+ local cleanup_directory=$(sanitize_pathname $cleanup_directory)
+ check_cleanup_settings
+ "check_"$user_mode"_directory" $cleanup_directory
+ [ $verbose -gt 0 ] && echo "Cleaning up $cleanup_directory by removing files older than $cleanup_older_than days."
+ find $cleanup_directory -type f -atime +$cleanup_older_than -print -exec rm {} \;
+ return 0
+}
+
function print_help () {
echo "help"
exit 0
}
-#TODO: Add function to cleanup backups
#TODO: Add function to mirror backups
#TODO: Add function to automatically add key to keyring, if not found
-#TODO: Add verbose flag
check_gpg_set
@@ -351,7 +370,7 @@ if [ ${#@} -gt 0 ]; then
while getopts 'c:hr:s:v' flag; do
case "${flag}" in
c)
- echo "Cleanup"
+ cleanup_mode=1
;;
h)
print_help
@@ -424,6 +443,8 @@ if [ -n "$source_mode" ];then
echo "Error. $source_mode is not a valid backup option."
exit 1
esac
+elif [ $cleanup_mode -eq 1 ];then
+ cleanup_backup
fi
exit 0