Backup automatically - google-apps-script

At our company we have a Google Spreadsheets which is shared by a link with different employees. This spreadsheet is saved on a Google Drive to which only I have access. The link is configured as such that anyone with the link can edit the spreadsheet since all employees need to be able to make changes to the file.
Although this is very useful, it also presents a risk in the form of data loss. If a user were to (accidentally) delete or alter the wrong data and saves the file, this data is permanently lost.
To prevent this I was wondering if it is possible to automatically have a backup created, say every day. Ideally, this backup is saved in the same Google Drive. I know I could install the desktop client and have the file backed up by our daily company backup, but it seems a bit ridiculous to install it for just one file. I'm sure there has to be another solution to this, ie with scripts.

I followed the advice of St3ph and tried revision history. Not exactly what I meant, but an acceptable solution nonetheless.

Related

Running python script on database file located in google drive

I have a database file which is located on my own google drive (private) and it's updated on a daily basis.
I wrote a python script in order to track the data from the database file, however I need to download the DB file to my pc, and then running my script locally, every single day.
I am wondering if there are any better options, so I wouldn't have to download the DB file and move it manually.
From a slight searching on the web I found that there is no way to run the script in the google drive folder (obviously due to security issues), and using google cloud platform is not a real option since it's not a free service (and as I understood there is no free trial).
Anyways, any method that would make my life easier would be happily accepted.
Sorry
That's not possible AFAIK. At least in the way you have asked the question.
It may be that you are looking for a Database hosting service, which, as a rule, are not free. I remember seeing a SQL viewer around, I don't know if it is still available and I don't think it was accessible via a local Python script.
Google Cloud Platform, as other services, do however offer a free tier of services - though this depends on how much use you need to give it and also on your location. Though this can get quite involved quite quickly. There are also various options to choose from. For example Big Query may be something you are interested in.
A Possible Workaround
I assume that the reason you don't want to download it is because it is tedious, and not because your network connection or hard drive can't handle it, if so:
The simple workaround may just be to find a way to automatically download the database via the (Google Drive API)[https://developers.google.com/drive] with your Python Script, modify it, or read it, and then upload it again if you need to. This can be done all within one script using the API. So all you would need to do is run the Python script and you wouldn't need to manually download and move it into a folder. You would also not need to worry about running over the free tier and getting billed for it.
You could even use the Google Drive Desktop software to keep the database file synced locally. Since it is local, I doubt the software would be able to block a Python script on the file system.
If you don't even want to think about it, you could set up the Python script with a CRON job or a Scheduled task if you are on Windows.

Automatically save a spreadsheet into an HTML file

I would like to know if there is a way to automate the process of saving a spreadsheet into an HTML file.
I have an OpenOffice spreadsheet that is located at a public file server inside my company´s LAN. A group of people work by editing and entering data into that spreadsheet, but others should only have read access. Since permissions policies can get a little bit complicated with OpenOffice, I thought it might be convenient for those who should only read the data to open the file in their web browsers by entering the route to the file or via a shortcut (specially since a lot of the read-only users are spreadsheet illiterates).
How can I achieve for this an HTML file to be updated every time the spreadsheet is saved by editing users, so read-only users can have the latest version?
Ideally, use a document management system that will keep older versions of the file to prevent mistaken edits by multiple people. Most DMS's provide some users with the ability to edit and others with the ability to read the document.
However, I once worked on a project where we used a large commercial DMS that was too complex for the read-only users. So we also ran a web server that provided read-only access to the documents.
Running a web server such as Apache HTTP Server, it is possible to do what you are asking even without a DMS. Provide a web form for people to submit edits to the document. When an edited document is submitted:
Save a copy of the old file.
Update the main version to the new file.
Run a command line job to convert the document to HTML.
Then read only users can view the HTML file by browsing to the web server.
Without a DMS or a web server, the best that can be done is to set file system permissions, as #mb21 said. That would certainly be easier to set up, and might be good enough depending on your needs.

Google Drive Sync + Read-only access

Here's the situation:
We use Google Apps for Business. We have one Google Drive folder -- "Folder A" -- that contains about 30 sub-folders. Each of these sub-folders contains hundreds of files and folders within it. You can assume that I am the owner of all files and folders on Google Drive. I am also the Google Apps superadmin. Folder A has a very well thought-out structure, with as many as eight levels of folders in the folder hierarchy. We need to share Folder A with 40 different computers -- folder structure, files, everything. These 40 computers are display terminals, so each is used by dozens of people every day. It's crucial for us that all 40 computers have exactly the same folder structure because people have to frequently move from one display computer to another, and they have to make a presentation in which every second matters, so we can't have them spend 5 to 10 minutes each time figuring out the folder structure of the computer they are standing at. For business reasons + potential delays, we can't have people sign in using their individual Google accounts.
Here's what I did:
created a new account ("display#domain.com")
shared Folder A with display#domain.com (at "can view" permission level)
on all 40 computers, logged in to display#domain.com's Google Drive and synced everything
My problem is
For some reason, Google Drive allows users to move, delete, or do pretty much whatever they want to folders and files -- even if they have only "can view" access. Yes, this doesn't affect the original shared folder / file, but is still a huge problem because:
If any random user goes to any of the 40 computers and accidentally deletes a file or moves it, then this affects the other 39 computers as well (because Google Drive syncs across all 40 computers)
Even if I share Folder A ("can view" access only) with 40 different new accounts (display1#domain.com, display2#domain.com, ...), a user can still mess up the folder structure by going to -- let's say -- computer 17 and moving or deleting folders. So everyone who uses computer 17 from that point onwards will struggle because the folder structure has been tampered with. Yes, the original Folder A, owned by me, will still be in perfect condition, so there is no data loss. But I have no way of knowing that the folder structure for computer 17 has been messed up. So to make sure that every computer has the correct folder structure just like my original Folder A, I need to manually go to each of the 40 computers every day and check or re-sync to Google Drive. That's going to be crazy!
So ideally we need some way to make Folder A read-only, i.e., users can access the content but can't tamper with the overall folder structure or delete files. We're open to getting creative solutions and happy to do as much work as required, as long as it's one-time work.
Your problem is the Drive Sync app which is bi-directional. If I understand you correctly, you want uni-directional sync. My recommendation would be to replace Drive Sync with your own app that implements the behaviour you're looking for.
I'm responding very late, but thought I'd share what I found (for future users with a similar problem).
Short version: there is no solution here. Google Drive will allow users to tamper with folder structures, even if they've been given only view access. Philosophically, Google probably wants each user to create his/her own folder structure.
Creating our own Google Drive lookalike, as pinoyyid suggested, wasn't really an option for business reasons (we're completely entrenched in the Google ecosystem so makes sense to stick to Drive). So what I end up doing is look through change activity in Google Drive (online, on my computer) on a daily basis, keeping an eye out for any changes to the folder structure. I then:
- undo that change
- approach the person who made that change and tell them they went wrong
Takes about 15 minutes per day
I will also eventually get around to automating this (using AppsScript I guess) but that's for later.
Thank you to all those who thought about the problem. Hopefully, Google will allow for a variety of use-cases at a later time.
I know this is an old question, but in case anyone else comes here looking for a solution, try using a different Google Drive Client. I've tried the programs WebDrive and RaiDrive before, and both of them offer the ability to use sync Google Drive to a virtual drive, and set the drive to read-only mode in the settings.
How about changing user permissions the local filesystems of all the 40 computers to "read only"? Should achieve the desired result.

how to sync files from mysql hosting site to google drive

We are creating a web application using MySQL as our database, is there a way that some files from the hosting site of our application can be sync to the user's google drive?
There's no direct way of synchronizing your local data with Drive.
However, you can pseudo-sync with little load on your server by using Changes. Basically, you can get list of file changes since the time you specify. If I were you, I make a cron job of checking file changes from Drive and Files.get specific files that have changed.
Besides what JunYoung Gwak suggests -> to ask google by polling them you will also have to keep a last edited date in your app and there might be cases when the local file is newer. will have to keep the same time zone as google to make it work for <24 hour changes.
So both sides will need to have a give changes since -date-time-in-timezone and a way to take a file for one place and update to the other.
Might have conflicts that need to be resolved by a diff tool.

How to map a Folder to a Table in SQL Server 2008?

I am using SQL Server 2008.
I have a table (TBL_FILE) that stores user uploaded files in binary column. However users do not want to open our system to access the file. They want to have a folder (network drive, Web folder, local drive, local folder... are accepted) that maps to the table (TBL_FILE). So they can directly open the file directly in File Explorer.
The key point is they want to open files directly in File Explorer.
Is it possible to do that? And what kind of program I need to write to do that? And how to do security?
Thanks!
Alex
Have you considered writing an application that would prompt for a login, then present a list of files to the user in a friendly user interface? You could drop a shortcut to that application in the folder they want these files to live in.
If you must have shortcuts directly from the filesystem into your binary data fields, then you are going to have to be a little bit hacky. Depending on how often the files are updated, you can try one of these options:
1 - Write an application that will run as a Windows Service or as a scheduled job. Periodically check for changed binary data, and save it to disk. Disadvantage: the file system will only be updated at intervals, so database changes will not be immediately available.
2 - Write a trigger on the table that saves the binary file to disk. Fire the trigger whenever the row changes- preferably by monitoring a 'last modified time' or similar field, rather than checking the binary value directly. The trigger could fire a CLR stored procedure, or you can do it directly from T-SQL using the method described here.
Disadvantage: You have a potentially time-consuming trigger on the table.
In either case, security becomes the problem of the Windows filesystem. Just grant access to the folder to whomever should see the files.
Good luck!
after searching in google, I finally find a solution of this problem.
We could create a logical drive with .NET technology or other third party libraries. One of the libraries is Doken http://dokan-dev.net/en/.
Doken is able to let us to create a drive in computer and do the logic ourselves. It seems that it is able to map a folder to a table in Database. But I haven't tried it yet.
Thanks!
Alex