0

I have a Google Drive folder in the cloud that I sync with my server to backup and restore a WordPress web directory and MySQL database dump and I accomplish this with rclone. I am able to see the entire directory tree with the following command:

root@ubuntu-server:~# rclone tree "Google Drive Backup:WordPress Backups"
/
└── 2020
    ├── November
    │   └── Sunday 29
    │       └── WordPress backup 29-11-20 (13.55.23).tar.gz
    └── October
        └── Thursday 15
            ├── WordPress backup 15-10-20 (12.15.11).tar.gz
            └── WordPress backup 15-10-20 (23.59.03).tar.gz

5 directories, 3 files

Overtime this list will be huge so I'm trying to implement a filter system to reduce it and find the file I need to see. I've created a little script that will ask a series of questions and set values to some variables from the user's input:

# Menu
clear
echo "What year would you like to see?"
read -p "Please enter the full year number below e.g. 2020:"$'\n> ' Year
clear
echo "What month would you like to see?"
read -p "Please enter the full month below (case sensitive) e.g. January:"$'\n> ' Month
clear
echo "What day would you like to see?"
read -p "Please enter the day below (requires two characters) e.g. 04:"$'\n> ' Day
clear

I want to essentially take the output of the rclone treecommand and filter it down with the values set in the variables. I currently have three variables:

  • Year
  • Month
  • Day

An example of filtering the directory tree with the grep command and one of the variables is:

rclone tree "Google Drive Backup:WordPress Backups" | grep $Month
rclone tree "Google Drive Backup:WordPress Backups" | grep November

The problem I'm facing is the child listings within that folder are not displaying and I'm left with the following:

root@ubuntu-server:~# rclone tree "Google Drive Backup:WordPress Backups" | grep November
    ├── November

I have the problem with searching for just 2020 as it should list child and grandchild directories but instead I'm left with this:

root@ubuntu-server:~# rclone tree "Google Drive Backup:WordPress Backups" | grep 2020
└── 2020

Once the directory tree is filtered to a substantiation amount I would like to turn each listing into a corresponding numbered option in a Bash script menu. The user of the script will simply type the number in the CLI and this will correspond with the file from the filtered list. This will save time trying to write out the whole file name path. If no filters are applied I've created a Yes/No prompt warning that this will display all backup files. If they decide to list all backups I want to limit the list to ten lines at a time. How do I achieve this? I thought about using the more command piped from the stdout to show only 10 items per page for example:

root@ubuntu-server:~# ls / | more -10
bin
boot
dev
etc
home
lib
lib32
lib64
libx32
lost+found
--More--

but hitting return on --More-- doesn't jump down another ten lines but rather only one line at a time.

1 Answer 1

0

rclone tree is meant to be visual, not to be fed to scripts. Try this instead:

$ rclone ls "Google Drive Backup:WordPress Backups"

Each line will have a full pathname. Now you can filter November 2020:

$ rclone ls "Google Drive Backup:WordPress Backups" | grep '-11-20'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .