Tasked with recovering files you don’t have access to through the web interface, you can always find these through the file system if you’re the operator. You could, of course, give yourself access, but let’s save that for another time. Right now we want the files our users removed and/or can’t find.
We start by looking for them in Owncloud’s data directory.
# find /mnt/data/owncloud/ -name "AWOL Excel file.xlsm*" /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542980717 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542029758 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542303810 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542631862 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1541686827 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1543226434 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542889051 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1541775363 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542722172 /mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1541922874
Oh hey, there they are!
So, now we could simply copy them and ship them to our user, but let’s be a bit more fancy, since we can.
# FILE_SUFFIX=".xlsm" # find /mnt/data/owncloud/ -name "AWOL Excel file.xlsm*" | > grep -E "\.v[0-9]+(\.d[0-9]+)?$" | > while read -r file; do > ts="${file##*.v}"; ts="${ts%.*}"; > date=$(date --date="@${ts}" +"%Y%m%dT%H%M%S") > base="$(basename "${file%.v*}")" > name="${base%${FILE_SUFFIX:-}}" > echo "${name}-${date}${FILE_SUFFIX:-}" > done AWOL Excel file-20181123T134517.xlsm AWOL Excel file-20181112T133558.xlsm AWOL Excel file-20181115T174330.xlsm AWOL Excel file-20181119T125102.xlsm AWOL Excel file-20181108T142027.xlsm AWOL Excel file-20181126T100034.xlsm AWOL Excel file-20181122T121731.xlsm AWOL Excel file-20181109T145603.xlsm AWOL Excel file-20181120T135612.xlsm AWOL Excel file-20181111T075434.xlsm
So that’s the list of our files, with all the names neatly timestamped (translated from the UNIX timestamp at the end of Owncloud’s file names).
Not setting the $FILE_SUFFIX variable will work fine too, but you will end up with names such as “AWOL Excel file.xlsm-20181126T100034”
Now, let’s copy the files to their new names in our current directory.
# FILE_SUFFIX=".xlsm" # find /mnt/data/owncloud/ -name "AWOL Excel file.xlsm*" | > grep -E "\.v[0-9]+(\.d[0-9]+)?$" | > while read -r file; do > ts="${file##*.v}"; ts="${ts%.*}"; > date=$(date --date="@${ts}" +"%Y%m%dT%H%M%S") > base="$(basename "${file%.v*}")" > name="${base%${FILE_SUFFIX:-}}" > cp -v "$file" "${name}-${date}${FILE_SUFFIX:-}" > done '/mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542980717' -> 'AWOL Excel file-20181123T134517.xlsm' '/mnt/data/owncloud/files/user/files_versions/Important/Stuff/AWOL Excel file.xlsm.v1542029758' -> 'AWOL Excel file-20181112T133558.xlsm' [... and so on ... ]
Cool.
Here it is as a one-liner, which your browser might add a line break to anyway, in case you’re interested:
FILE_SUFFIX=".xlsm"; find /mnt/data/owncloud/ -name "AWOL Excel file.xlsm*" | grep -E "\.v[0-9]+(\.d[0-9]+)?$" | while read -r file; do ts="${file##*.v}"; ts="${ts%.*}"; date=$(date --date="@${ts}" +"%Y%m%dT%H%M%S"); base="$(basename "${file%.v*}")"; name="${base%${FILE_SUFFIX:-}}"; cp -v "$file" "${name}-${date}${FILE_SUFFIX:-}"; done