Skip to content

[Feature Request] php occ trashbin:restore #18921

Closed

Description

@Sour4pple

Hey there!

I am dealing with customers, who sometimes delete files on their Nextcloud in huge quantities by accident. Restoring thousands of files through the webgui is pretty tedious. I know, you can select all files, but still it doesn't work clean for so many files, since it brings the web interface to it's limit (in my experience).

Now my suggestions would be to add a command line option to solve this easier in the future. Personally I'd add the option restore to the existing php occ trashbin command. Some useful arguments to define would probably be usernames to locate the correct trashbin and a verbose option.

Thanks for your work.

Best regards,
Tim

Activity

  1. alejandroscf commented on Apr 16, 2020

    @alejandroscf

    That would be a great option. I just had to restore a backup from the previous day because with the webui was impossible.

  2. bseclier commented on Dec 7, 2020

    @bseclier

    It would be a great feature, indeed !

  3. benoitlavorata commented on Dec 23, 2020

    @benoitlavorata

    I have the same issue on a server for a customer. The webUI is just too slow to restore all these files.
    As I did not find any commands to restore the whole trashbin for a given timeframe, I made a snippet in Chrome to automate the click on "restore" for all the files deleted for a given period.

    • Definitely not perfect, but hopefully it can help someone.
    • Just change the dates in the function call at the bottom of the snippet.
    • You must be on the trashbin page, logged in with the user you want to restore files for.
    • Use at your own risks - this is only meant to help other admins with the same issues.
    • Edit: modified the timer between each restore (2000), as faster was making NC miss some files.
    • Edit2: debugged the code below as I had a similar issue with a customer.
    // NEXTCLOUD RESTORE
    
    // I have the same issue on a server for a customer. The webUI is just too slow to restore all these files.
    // As I did not find any commands to restore the whole trashbin for a given timeframe, I made a snippet in Chrome to automate the click on "restore" for all the files deleted for a given period.
    
    // Definitely not perfect, but hopefully it can help someone.
    // Just change the dates in the function call at the bottom of the snippet.
    // You must be on the trashbin page, logged in with the user you want to restore files for.
    // Use at your own risks - this is only meant to help other admins with the same issues.
    
    let restoreFiles = async function(opts) {
        let sleep = async function(timer) {
            return new Promise(res=>{
                setTimeout(()=>{
                    res(true)
                }
                , timer)
            }
            )
        }
    //     console.log(opts)
    
        if(!opts['index']){
            opts['index'] = 0
        }
        index = opts['index']
    
        console.log(`PAGE: ${index}`)
    
        for (var i = 0; i < opts.preScrollPagesCount; i++) {
            await sleep(1000 * opts.waitBetweenScrolls)
            $("html, body").animate({ scrollTop: $(document).height() }, 1000);
        }
        await sleep(1000*opts.waitAfterScroll)
        
    
        let restoreBtns = $('.action-restore')
        let start = moment(opts.startDate)
        let end = moment(opts.endDate)
        for (var i = 0; i < restoreBtns.length; i++) {
            let btn = $(restoreBtns[i])
            let section = btn.parent().parent().parent()
            let tr = section.parent()
    
            let path = tr.attr('data-path')        
            let file = tr.attr('data-file')
            let mtime = tr.attr('data-mtime')
           
            if (!mtime)
                continue;
    
            let mMoment = moment(parseInt(mtime))
            if (!(mMoment.isBefore(end) && mMoment.isAfter(start)))
                continue;
    
            console.log(`Restore: ${path}`)
            await sleep(opts.waitBetweenClicks * 1000)
            btn.click();
        }
    
        await sleep(opts.waitBeforeLoop * 1000)
        opts['index'] = opts['index'] + 1
        return restoreFiles(opts)
    }
    
    clear();
    
    // // Sort by Ascending deleted time (recent => old)
    // $('#modified').click()
    // $('#modified').click()
    
    restoreFiles({
        startDate: '2021-03-30 11:00:00', 
        endDate: '2021-03-31 13:00:00',
        waitBetweenClicks: 5,
        waitAfterScroll: 10,
        waitBetweenScrolls: 1,
        waitBeforeLoop: 4,
        preScrollPagesCount: 2
    })
  4. jabdoa2 commented on Feb 7, 2021

    @jabdoa2

    As I have been hit by nextcloud/desktop#260 as well this would be useful to me too.

  5. added
    1. to developAccepted and waiting to be taken care of
    and removed
    0. Needs triagePending check for reproducibility or if it fits our roadmap
    on Jul 2, 2021
  6. szaimen commented on Jul 2, 2021

    @szaimen
    Contributor

    Currently no one is working on this one, so it would be great if someone of you could open a PR to implement this :)

  7. martijnvandijk commented on Sep 24, 2021

    @martijnvandijk

    You, @benoitlavorata just helped me out big time with your snippet! Thank you so much for sharing.

  8. Tie-fighter commented on Feb 7, 2022

    @Tie-fighter

    I need this so badly after my desktop client decided to mark files as deleted instead of freeing up disk space 😅

    PS: Doing it in bulk via the GUI spawns a lot of connections, the server even runs out of memory (16GiB), starts swapping, dropping connections and spawning errors. (Despite me disabling filelocking for the restore).
    Maybe some kind of rate limiting or optimization could help here.
    Bulk restore is unusable like this 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions