Hi.
Is it possible to allow you to delete the created / changed files for more than n days?
It seems to me that it was more valuable for the application, as it allowed a more careful management of the files.
Hello,
I'd also like this. It helps managing backup files.
Here's a script I threw together that uploads a file and deletes all files which are older than 100 days in a given directory. It assumes that you have the gdrive executable in the same directory as the script.
````bash
set -e;
if [ $# -le 2 ]
then
echo "Usage: ./backup.sh [platform] [gdrive folder id] [file to backup]";
exit 1;
fi
directory=dirname "$0"
gdrive=$directory/gdrive-$1
backup_directory_id=$2
file_to_backup=$3
$gdrive upload --parent $backup_directory_id $file_to_backup;
hundred_days_ago=python -c 'from datetime import datetime as dt, timedelta as delta; print((dt.now() - delta(days=100)).strftime("%Y-%m-%d"))';
expired_backups=$gdrive list -m 1000 --query " ('$backup_directory_id' in parents) and trashed = false and modifiedTime < '$hundred_days_ago'" --order "modifiedTime asc" --no-header | cut -d ' ' -f1;
while read -r backup_id; do
echo Deleting $backup_id;
$gdrive delete $backup_id;
done <<< "$expired_backups"
````
Example usage:
./backup.sh linux-x64 0BwFfewfewwf-ofewfwF2WHM example.db
why phyton?!!
date --date="-10 days" +%Y-%m-%d
Because it is a script, and it works just fine, and I鈥檓 giving it away for free. That鈥檚 why?!!
@michaelmcmillan Thank you very much for your script! However I麓ve made some changes to my needs, Here bellow, and it is working:
set -e;
#echo "Usage: ./backup.sh [gdrive folder id] [file to backup]";
#exit 1;
directory=dirname "$0"
backup_directory_id=$2
file_to_backup=$1
gdrive sync upload $file_to_backup $backup_directory_id;
hundred_days_ago=python3 -c 'from datetime import datetime as dt, timedelta as delta; print((dt.now() - delta(days=1)).strftime("%Y-%m-%d"))';
expired_backups=gdrive list -m 1000 --query " ('$backup_directory_id' in parents) and trashed = false and modifiedTime < '$hundred_days_ago'" --order "modifiedTime asc" --no-header | cut -d ' ' -f1;
while read -r backup_id; do
echo Deleting $backup_id;
gdrive delete $backup_id;
done <<< "$expired_backups"
I麓ve comment the first lines because I don麓t need instructions(kkkkkk), and since I want to delete always the last file that I麓ve previous uploded. I hope this help someone.
To use you simple have to do ./backup.sh folder gdrive-folder-id
Most helpful comment
Here's a script I threw together that uploads a file and deletes all files which are older than 100 days in a given directory. It assumes that you have the
gdriveexecutable in the same directory as the script.````bash
!/usr/bin/env bash
set -e;
if [ $# -le 2 ]
then
echo "Usage: ./backup.sh [platform] [gdrive folder id] [file to backup]";
exit 1;
fi
Arguments
directory=
dirname "$0"gdrive=$directory/gdrive-$1
backup_directory_id=$2
file_to_backup=$3
Backs up the current file
$gdrive upload --parent $backup_directory_id $file_to_backup;
hundred_days_ago=
python -c 'from datetime import datetime as dt, timedelta as delta; print((dt.now() - delta(days=100)).strftime("%Y-%m-%d"))';expired_backups=
$gdrive list -m 1000 --query " ('$backup_directory_id' in parents) and trashed = false and modifiedTime < '$hundred_days_ago'" --order "modifiedTime asc" --no-header | cut -d ' ' -f1;Deletes backups that are more than 100 days old.
while read -r backup_id; do
echo Deleting $backup_id;
$gdrive delete $backup_id;
done <<< "$expired_backups"
````
Example usage:
./backup.sh linux-x64 0BwFfewfewwf-ofewfwF2WHM example.db