syncloud / platform

Run popular services on your device with one click
https://syncloud.org
GNU General Public License v3.0
400 stars 40 forks source link

Backup clarification and Download option #410

Closed klmhsb42 closed 1 year ago

klmhsb42 commented 5 years ago

(1) What is inside the backup files? (2) Add Download links each file (+ Download all button) (3) Info, how to backup SD/System (Link to Wiki)

klmhsb42 commented 5 years ago

I'm trying to add this, but I need some help. I edited backup.html and backup.js https://github.com/syncloud/platform/compare/master...klmhsb42:master

I need to know: (1) Which backup script do I need to run to zip all? Because then I would set a link to this file (Download all) (2) Where are the tar.gz files stored (can't find them under /data/platform/backup), I would like to set a download link with: (3) Where are the scripts for restore and remove, I would like to adapt them as download script. (4) I would add a upload script as well to upload files

cyberb commented 5 years ago

First of all you are making changes on outdated master branch so that is why it always shows all the past changes which may have been already merged to remote master branch. You need to add remote:

git remote add syncloud https://github.com/syncloud/platform.git

Fetch latest changes:

git fetch syncloud

Create a branch for a feature

git checkout -b feature syncloud/master

Make (commit) some changes and push to your repo (origin) as you cannot push to syncloud

git push feature origin

Then you can create a pull request on github.

As to the questions:

  1. Do you want to zip all the zips into one zip file? It may be very big, but OK. Most of the code for the backup/restore logic is inside new backend which is written in go lang here: https://github.com/syncloud/platform.git There are still two low level scripts in bash which go call still but they will be ported to go at some point. I would dowload all in pure go as a new backup rest end point.
  2. Backup files are in /data/platform/backup, Check using ls.
  3. Remove is pure go (Remove func).
  4. Upload should also be done in go as a new rest endpoint.
klmhsb42 commented 5 years ago

Thanks for the help.

What is your workflow on local desktop? I would like to make changes on a running syncloud to see changes and also I need a complete installation to have data directory, apps, etc... Or do I have to modify platform and then to create an new image and then start it with VM?

I can see how you are calling bash scripts with go scripts, but I don't get in which line of backup.js you are calling go scripts. Is it $.get('/rest/backup/restore', { file: file }, () => { reload(); })?

Do you remove backup files completly or move them to some trash folder? And if an app is restored by backup file, what happens with the current app data? Is it displaced completly? If so, it would be nice to create a backup before restoring...

cyberb commented 5 years ago

Just in case my desktop is Ubuntu.

If I am changing backend (python, go) usually I just write unit tests for vatious pieces (you do not have to do it just for trying things) and in the end build a platform package and just install it over existing platform on a device.

Sone info here: https://github.com/syncloud/platform/blob/master/README.md#building-a-package-locally

The usual architecture of a web app is the following:

  1. Web server (nginx) serves static files (html, js, css)
  2. Browser executes them and js calls web server urls (/rest/backup/restore) as it cannot execute bash, go, python by many reasons.
  3. Web server knows special urls and talks to backend (python or go in oir case) processes. Eventually python one will be removed

When backup is removed it is removed completly (no trash). Restore removes all app configs from previous installation, you can crrate an issue to offer a backup before restoring.

klmhsb42 commented 5 years ago

I'm trying to create buttons after the grid in the backup.js


const backupallOptions = () => {    
                  var div2 = document.createElement('div');
                  div2.innerHTML = `
                   <button class="submit buttongreen control" id="" type="submit" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Working..."  style="width: 150px">Download all</button>
                   <button class="submit buttongreen control" id="" type="submit" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Working..."  style="width: 150px">Backup all</button>
                   <button class="submit buttonblue control" id="" type="submit" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Working..."  style="width: 150px">Restore all</button>
                   <button class="submit buttonred control" id="" type="submit" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Working..."  style="width: 150px">Delete all</button>
                 `;
                  var buttons = div2.querySelectorAll('i');
                  buttons[0].addEventListener('click', () => { 
                      $('#backup_file').val(params.data.file);
                      $('#backup_action').val('downloadall');
                      $('#confirm_caption').html('Download');
                      $('#confirm_question').html('Do you want to download all backup files?');
                      $('#backup_action_confirmation').modal('show');
                  });
                  buttons[1].addEventListener('click', () => { 
                      $('#backup_file').val(params.data.file);
                      $('#backup_action').val('backupall');
                      $('#confirm_caption').html('Backup');
                      $('#confirm_question').html('Do you want to backup all apps?');
                      $('#backup_action_confirmation').modal('show');
                  });
                  buttons[2].addEventListener('click', () => { 
                    $('#backup_file').val(params.data.file);
                    $('#backup_action').val('restoreall');
                    $('#confirm_caption').html('Restore');
                    $('#confirm_question').html('Do you want to restore all apps from respective latest backup?');
                    $('#backup_action_confirmation').modal('show');
                  }); 
                  buttons[3].addEventListener('click', () => { 
                    $('#backup_file').val(params.data.file);
                    $('#backup_action').val('removeall');
                    $('#confirm_caption').html('Remove');
                    $('#confirm_question').html('Do you want to remove all backup files completely?');
                    $('#backup_action_confirmation').modal('show');
                  }); 
                  return div2;                                                
};

And to show it with the existing function:

$( document ).ready(function () {
  let backupallbuttons = document.querySelector('#backupAll');
  //backupallbuttons.innerHTML += backupallOptions;
  backupallbuttons.appendChild(backupallOptions); 
  reload();
});

But innerHTML shows only everything inside the function as text and appendChild shows nothing. Any idea?

Of course <div id="backupAll" style="margin-top: 2%;"></div> exists in backup.html.

cyberb commented 5 years ago

You are not calling backupallOptions function. You need to call it with backupallOptions()

klmhsb42 commented 5 years ago

I tried but nothing happens. I guess maybe div2 is not returned? Or it breaks the function after backupallOptions().

$( document ).ready(function () {
  let backupallbuttons = document.querySelector('#backupAll');
  backupallOptions();
  backupallbuttons.appendChild(div2); 
  reload();
});
cyberb commented 5 years ago

You are not using the returned div now.

$( document ).ready(function () {
  let backupallbuttons = document.querySelector('#backupAll');
  backupallbuttons.appendChild(backupallOptions()); 
  reload();
});
klmhsb42 commented 5 years ago

That's what I tested, too. I don't get any output on the html page. Maybe backupallOptions() breaks somehow?

cyberb commented 5 years ago

Check what browser's developer tools says (F12), console tab.

cyberb commented 5 years ago

You can also debug your js there.

klmhsb42 commented 5 years ago

Or just reading docs :) https://www.w3schools.com/jsref/met_document_queryselectorall.asp

var buttons = div2.querySelectorAll('button'); instead of var buttons = div2.querySelectorAll('i');

cyberb commented 5 years ago

Also, you do not have to create these elements programmatically in js, they can be simply added to html herr below the grid: https://github.com/syncloud/platform/blob/master/www/public/backup.html#L18

You need to use js for more dynamic content, for example grid row buttoms are easier to create dynamically.

cyberb commented 1 year ago

Stale