Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/scripts/rebuild_projects.py
Views: 687
###############################################################################1#2# CoCalc: Collaborative Calculation3#4# Copyright (C) 2016, Sagemath Inc.5#6# This program is free software: you can redistribute it and/or modify7# it under the terms of the GNU General Public License as published by8# the Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU General Public License for more details.15#16# You should have received a copy of the GNU General Public License17# along with this program. If not, see <http://www.gnu.org/licenses/>.18#19###############################################################################2021import argparse, hashlib, os, random, time22from subprocess import Popen, PIPE232425def cmd(s):26print(s)27out = Popen(28s, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=not isinstance(s, list))29x = out.stdout.read() + out.stderr.read()30e = out.wait()31return x323334def all_projects(filename='projects'):35return [x.strip() for x in open(filename).readlines() if x.strip()]363738def rebuild(project_id):39if 'does not exist' not in cmd("zfs list projects-new/%s" % project_id):40print("%s already done" % project_id)41return42if project_id in ''.join(cmd('ps ax')):43print("skipping since %s is in progress, evidently" % project_id)44return45v = cmd("zfs list -r -t snapshot projects/%s|tail -1" % project_id).split()46print(v)47if len(v) < 2:48return # nothing to do49try:50cmd("time zfs send -Rv %s 2>>log | mbuffer -s 256k -m 8G -o - | zfs recv -vu projects-new/%s 2>>log"51% (v[0], project_id))52except:53cmd("zfs destroy -r projects-new/%s" % project_id)545556def rebuild_all(filename='projects', reverse=False):57i = 058t0 = time.time()59v = all_projects(filename=filename)60if reverse:61v = list(reversed(v))62for p in v:63i += 164print("%s / %s: %s" % (i, len(v), p))65t = time.time()66rebuild(p)67print(time.time() - t) / 60, " (total time=%s minutes)" % (68(time.time() - t0) / 60)697071