Google Drive Monitor – Get Email Alerts When Files are Deleted in your Drive


Monitor your Google Drive automatically and get email alerts when important files and folders are deleted from your Google Drive. You can also watch file activity in Shared Drives

Published in: Google Apps ScriptGoogle Drive

When you delete a file in Google Drive, it moves to the trash folder and stays there indefinitely until you manually empty the bin. That is how it has always been but, sometime this month, Google made one important change to how the trash bin works.

Under the new policy, files that have been in Google Drive’s trash bin for more than 30-days are automatically deleted. This automatic cleanup does help reclaim space but if you happen to accidentally delete some important files or folders from your Google Drive, there’s no way to restore them from the trash after the 30-day window.

Monitor Google Drive Files

If you are like me who is terrified at the prospect of forever losing important files that were deleted by mistake, Google Drive Watch can help.

Google Drive Watch is an open-source Google Script that automatically monitors your Google Drive and sends daily email notifications with a detailed list of files that were deleted the previous day.

Here’s a sample email notification sent by the Google Drive Watch program.






The email includes the file link, the date when the file was first created, and the name/email address of the Google Account that last modified and deleted the file. It monitors files in your regular Google Drive as well as Shared Drive folders.

Watch your own Google Drive

Here’s how you can set up Google Drive watch for your own Google account in few easy steps:

  1. Click here to make a copy of the Google script in your own Google Drive.

  2. Inside the script editor, go to line #9 and specify the email address where you want to receive the Drive notifications. You can also put multiple emails separated by commas.

  3. The script, by default, will create a cron job that will run once per day at the selected hour. If you however wish to change the frequency so that the notifications arrive, say, every 5 days, you can specify 5 in line #10.

  4. We are almost there. Go to the Run menu and choose “Enable Drive Watch” to enable the monitor for your Drive. Allow the script to access your file and you are all set.




Configure Google Drive Watch Email

Important: The first email notification will only arrive the next day at the selected hour.

How Google Drive Monitoring Works

The source code of the Google Drive monitor script is available on Github.

Internally, the script uses the Google Drive API with Google Apps Script to watch for changes in your Google Drive. It then sets up a daily cron job, using triggers in Google Scripts, that sends the email if new file changes are found.

When you first run the script, it gets a starting page token and all changes made to Google Drive after this token is fetched will be monitored by the script. We set supportsAllDrives to true since the script should monitor folders in Team Drives as well.

function getPageToken() {
  const store = PropertiesService.getScriptProperties();
  const token = store.getProperty('token');
  if (token) return token;
  const { startPageToken } = Drive.Changes.getStartPageToken({
    supportsAllDrives: true,
  });
  store.setProperty('token', startPageToken);
  return startPageToken;
}

The change.list endpoint of the Google Drive API fetches all changes made to the authorized user’s Drive since the start page token. We also set the fields property to limit file properties that are available in the response. The newStartPageToken returned in the response will become the new page token for future calls to the Drive API.

const fields = `newStartPageToken,
  items(file(id,title,labels(trashed),
  iconLink,mimeType,createdDate,ownedByMe,
  lastModifyingUser(emailAddress,displayName,picture(url)),
  alternateLink, fileSize))`;

const { newStartPageToken, items = [] } = Drive.Changes.list({
  fields,
  pageToken: getPageToken(),
  includeItemsFromAllDrives: true,
  pageSize: 100,
  supportsAllDrives: true,
});

if (newStartPageToken) {
  propertyStore.setProperty('token', newStartPageToken);
}

The items array holds a list of files that have been modified since the last run. This also includes new files that have added and old files that were edited by the users. Since we are only interested in the file that have been trashed, we’ll filter all files from the response except the ones that have been trashed.

const filteredItems = items
  .map(({ file }) => file)
  
  .filter(({ ownedByMe }) => ownedByMe)
  
  .filter(({ labels: { trashed } = {} }) => trashed === true)
  
  .map((file) => {
    const {
      iconLink,
      alternateLink,
      title,
      lastModifyingUser = {},
      createdDate,
      fileSize,
    } = file;
    return { iconLink, alternateLink, title, createdDate, fileSize };
  });

Now that we have an array of files that have been deleted by the user since the last run, we can use the Gmail service to notify the user.

Also see: Google Drive URL Tricks



Source link

Two Victorian schools closed as COVID cases spread to social housing block, Alerts for Bathurst 1000 visitors after virus found in raw sewage, Coronavirus cases surge across US, Australia death toll at 905


“This timeframe allows for the department to ensure the community is aware of the situation and for residents to get tested and get their results back before determining what the next steps are,” Victoria’s commander of testing and community engagement, Jeroen Weimar, said.

“We’re asking all these residents to come forward for asymptomatic testing at the dedicated testing station on site.”

The East Preston Islamic College has been closed for deep cleaning after it was revealed a student who was supposed to be self-isolating as they were a close contact of a positive case had attended school due to a misunderstanding.

“The college has taken positive steps to manage this situation and is working closely with us. It has been closed for deep cleaning,” Mr Weimar said.

“We need everyone working together to tackle this virus, and that’s exactly what the school community is doing. Staff and students who are close contacts – and their households – have been identified and are quarantining for 14 days.

“Extensive contact tracing is underway and we expect that as part of this work, additional cases will be detected.”

The Dallas Brooks Primary School has also been closed for deep cleaning.

A text message was sent to residents in the northern suburbs, urging them to get tested if they experienced any symptoms.

Pop-up testing sites and a community outreach program will be launched today.

Banyule Community Health and Himilo Community Connect will doorknock the area on Thursday to alert residents to the outbreak and provide information about testing and supports like financial assistance for missing work.

“We’re asking everyone who lives in this area or who has loved ones linked to these suburbs to please get tested if they have symptoms and to share this information within their families and broader community,” Mr Weimar said.



Source link

Victoria COVID-19 cases continue to decline, NSW health alerts issued for inner-Sydney venues, Australia death toll at 652


Premier Daniel Andrews will announce plans to reopen on Sunday, a week before September 13.

Professor Blakely said Victorians, including himself, were fed up with stay-at-home orders but said re-opening was risky with case numbers about 30 per day.

“You [can] resurge again and you get the cases coming back. So it’s really important to strike the balance here. I am sick of lockdown, we are all sick of lockdown, but we need to come out where we don’t have a wave coming in that will have us back in lockdown by Christmas,” he said on Nine’s Today program.

Loading

Professor Blakely said it was possible the state could open up and suppress cases effectively if testing rates remained high, businesses operated safely and people continued to wear face masks.

“There’s a lot of things that need to be done well. Contact tracing needs to be done much better by the Victorian government than previously has been the case,” he said.

“Us as citizens [need to be] using masks in those outdoor environments and be sensible and not have mass group gatherings. It’s a very different world but it’s our reality.”



Source link

Automated Water Alerts Now Available in Derwent Valley


A monitoring station. Images in this post courtesy Hydro Tas.

River users and landowners in the Derwent Valley can now automatically be kept informed on changing water levels thanks to innovative technology from Hydro Tasmania.

A new system of water level notifications provides customised SMS, email and text-to-speech alerts from Hydro Tasmania’s remote sensors, advising subscribers of water levels for business or recreational purposes.

Hydro Tasmania CEO Steve Davy said the business wanted to look after its neighbours. “We been speaking with farmers downstream from our dams and heard about irrigation pumps either being drowned or running dry every few years due to changing water levels, and the cost of repairs that start at $3,000 per pump,” he said.

He said this may be particularly concerning for farmers with sensitive crops, who need to plan their irrigation to get the best yields.

“A farmer in the lower Derwent may not be aware of rain upstream in the river system that is causing water levels in our dams to rise, until they spill, and because changing water levels can impact users in different ways, our new water alert system will let you subscribe to a range of alerts depending on your needs,” Davy explained.

This information has been available on the website for many years, but Hydro say they wanted to go a step further. “After our initial tests with local users in the Derwent Valley were successful, we’ve used their feedback to help develop the final product, ”

He said the system is now to the public, and river users such as canoeists and kayakers for example can also take advantage, as the alerts will let advise them of increased flows, and enable them protect their equipment.

The new system is for water level changes that are smaller than those in flood alerts from the Bureau of Meteorology (BOM) and that Hydro Tasmania can only provide information about the waterways it manages. People should continue to check information from BOM and State Emergency Services in the event of a flood.

The new water alerts system is initially available for the Derwent and Ouse rivers only, but will be expanded to the Mersey Forth, King, South Esk and Pieman rivers over the next two years. The system will be tailored during the rollout based on ongoing feedback from users.

“Once again, congratulations to Hydro Tasmania for developing this water level alerts system and we look forward to seeing the benefits flowing across the state in coming years,” said Minister for Primary Industries and Water Guy Barnett.

The Hydro alerts can be found here. A (free) registration is required to access the alerts.

Author Credits: [show_post_categories parent=”no” parentcategory=”writers” show = “category” hyperlink=”yes”]



Source link